After moving our build agents from one server to another, one of the builds no longer worked. When looking at the logs, I noticed that the build failed almost immediatelly with the following error message:
No agent found in pool Azure Pipelines which satisfies the specified demands: java
And indeed when I took a look at the specific pipeline demands I could see that java was required. Turns out that the SonarQube analysis requires java installed on the build server to be able to execute. As the build server was a new clean install, nothing was installed yet.
Install Java OpenJDK
Time to fix that…
The license terms of the Oracle JDK has changed and updates are no longer free. Therefore I choose to install the Azul OpenJDK(download it here).
I used the MSI and walked through the installation wizard. After completing the setup I manually created the JAVA_HOME environment variable and set it to the bin folder of the Zulu installation(e.g. C:\Program Files\Zulu\zulu-11\bin\)
Normally this last step is not required but for an unknown reason, the environment variable wasn’t created by the installer.
Rescan for capabilities
Now it is time to update the agent capabilities. To trigger a rescan, the agent should be restarted. The agents were running as windows services so I went to the services screen and restarted the specific services. After doing that, the environment variable was detected as part of the capabilities:
Unfortunately this didn’t solve the issue and when I tried to rerun the build it still failed with the same error message.
In the SonarQube documentation I found the following:
If you add a Windows Build Agent and install a non-oracle Java version on it, the agent will fail to detect a needed capability for the SonarQube Azure DevOps plugin. If you are sure that the
java
executable is available in thePATH
environment variable, you can add the missing capability manually by going to your build agent > capabilities > user capabilities > add capability. Here, you can add the key, value pair java, and null which should allow the SonarQube plugin to be scheduled on that build agent. This Bug has been reported to the Microsoft Team with azure-pipelines-agent#2046 but is currently not followed up upon.
Add user capability
Let’s follow the suggestion mentioned above and add the capability ourselves:
- Go to Project Settings –> Agent Pools. Select the pool that contains the agent.
- Go to the agents tab and select the agent from the pool.
- Go to the capabilities tab and click on the ‘+’ sign to add a user defined capability.
- Enter ‘java’ in the name field and leave the value field empty. Click Add.
Repeat this process for every agent that you want to be able to run this build.