No, this is not a post on global warming. As it turns out, I have been provisioning my Azure DevOps build agents somewhat incorrectly, at least for certain toolsets.
Sonar kicks it off
It started with this error in my build pipeline:
The version of Java (11.0.21) used to run this analysis is deprecated, and SonarCloud no longer supports it. Please upgrade to Java 17 or later.
As a temporary measure, you can set the property 'sonar.scanner.force-deprecated-java-version' to 'true' to continue using Java 11.0.21
This workaround will only be effective until January 28, 2024. After this date, all scans using the deprecated Java 11 will fail.
I provision my build agents using the Azure DevOps/GitHub Actions runner images repository, so I know it has multiple versions of Java. I logged in to the agent, and the necessary environment variables (including
JAVA_HOME_17_X64) are present. However, adding the
jdkVersion input made no difference.
- task: SonarCloudAnalyze@1
I also tried using the
JavaToolInstaller step to install Java 17 prior, and I got this error:
##[error]Java 17 is not preinstalled on this agent
Now, as I said, I KNOW it’s installed. So, what’s going on?
All about environment
The build agent has the proper environment variables set. As it turns out, however, the build agent needs some special setup. Some research on my end led me to Microsoft’s page on the Azure DevOps Linux Agents, specifically, the section on environmental variables.
I checked my
.env file in my agent directory, and it had a scrawny 5-6 entries. As a test, I added
JAVA_HOME_17_X64 with a proper path as an entry in that file and restarted the agent. Presto! No more errors, and Sonar Analysis ran fine.
Scripting for future agents
With this in mind, I updated the script that installs my ADO build agent to include steps to copy environment variables from the machine to the
.env file for the agent, so that the agent knows what is on the machine. After a couple tests (forgot a necessary
sudo), I have a working provisioning script.