Configuring Java version for TeamCity
Asked Answered
T

2

8

We have installed TeamCity on an OpenSuse machine. the version of TeamCity is 9.1.3.

I have installed JDK 1.8 on the server but I am not using it as default Java. I want to update every Agent to build with new JDK (version 8) and if update was successful for all of agents then I will try to upgrade JDK for whole system.

I couldn't find an easy way for running an agent or project with specific JDK version. I am used to with Jenkins and there it was pretty easy to use different JDK for builds.

I looked at Team city documentation but couldn't find any real instruction how can we use an specific Java version for a project or agent.

Any help?

Tendency answered 2/3, 2018 at 8:54 Comment(2)
just create an env variable JAVA_HOME="" on each agent or confiruration paramsWait
Exporting only JAVA_HOME might not be enough, some of TeamCity agents I work with are not able to detect all the available JDKs on the system.Needful
C
4

The page you are looking for is this one. As Senior Pomidor said its enough to specify that environment variable.

Running several jdk's on an agent to support builds with different java versions is described on this page.

Conjugate answered 2/3, 2018 at 22:17 Comment(1)
thanks @Conjugate for your answer. I saw those pages by myself. The problem is that when I am checking Agent parameters there are some wrong agent parameter like JDK_16 /usr/java/latest which in this case the latest for my installation is jdk18. I want to find the place defining this and change itTendency
E
3

In your build configuration run three dots next to run button. Under the parameters tab, you can pass custom build parameters.

enter image description here

You can also have set environment bash script in your source code which overrides

#!bin/bash
echo "##teamcity[setParameter name='env.JAVA_HOME' value='/usr/lib/jvm/java-11-openjdk-amd64']"

Include this script as part of build steps enter image description here

file=%system.teamcity.build.checkoutDir%/teamcityEnv.sh
echo "File : $file"
if [ -e "$file" ]
then
    echo "teamcityEnv file: '$file' found. Setting up the Env variables"
    sh $file
else
    echo "teamcityEnv not found. Skipping env setup"
fi
Elmoelmore answered 16/6, 2021 at 6:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.