Search code examples
javadockercontinuous-integrationteamcity

How to install Java 11 in TeamCity?


I'm a junior developer introducing unit testing to a project using SBT with Java 11. In my team of 3, they never wrote any kind of unit testing.

We are planning to start it now.

We have a self-hosted TeamCity CI/CD setup for unit testing. The default TeamCity runner agent (Docker) uses Java 17.

How can I install Java 11 within the existing runner or create a new runner with Java 11?

Installed runner using this

docker run -e SERVER_URL="http://<My self hosted server URL>:8111" jetbrains/teamcity-agent

Solution

  • Steps to install Java 11 in TeamCity via Docker :**

    1. Create a Docker file.

      FROM jetbrains/teamcity-server:latest
      RUN apt-get update && \
          apt-get install -y openjdk-11-jdk
      ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64
      RUN update-alternatives --set java $JAVA_HOME/bin/java
      EXPOSE 8111
      CMD ["/opt/teamcity/bin/teamcity-server.sh", "run"]
      
    2. Build the Docker file via below command:

      docker build -t teamcity-with-java11
      
    3. Run the Teamcity container via below command:

      docker run -it --name teamcity-instance -p 8111:8111 teamcity-with-java11
      

    Once the container is up and running, try to access TeamCity via http://localhost:8111.