If you decided to go with a self-hosted agent(s) as I described in one of my previous articles, you might run into specific runtime issues related to the absence of a framework or software installed on a target machine. One such error is “[error] No agent found in pool … which satisfies the specified demands: java Agent.Version -gtVersion 2…x”. The ways it looks in Azure Pipelines:
The error message is not that self-explanatory, but this one means the agent installed on a target machine (the one you use for build purposes) cannot find Java. Why do you need Java for building .NET projects, you may ask? In this case, the agent needs it if you’re using SonarQube (SonarCloud) in your build tasks. I explained the way SQ works with Azure Pipelines here.
To resolve this error, you have to install Java. JDK downloaded from here would do: https://www.oracle.com/ca-en/java/technologies/javase-downloads.html
The next step after installation is a minor configuration, so the agent can ‘recognize’ it. For that matter, you need to add two environment variables (in the case with Windows machine). In the case of a Linux-based build server, the installation would be sufficient.
The fist variable is %JAVA_HOME%. It needs to point to a specific version of the Java development kit you just installed:
NOTE: To get to this window, go to the search field next to the Start button in windows and type ‘View advanced system settings’. In the appeared window, click ‘Environment variables…’ button.
Now we can proceed with the second one. You need to add a path to a ‘bin’ folder:
After that, you can test Java installed via the command line with the following commands:
Every command should produce the expected result that matches the Java version you installed:
For the changes to take effect, there is no need to restart the entire machine (even though you should, for the older versions of Windows). You can simply restart the agent services. For that, type ‘Services’ in the search box (you already know where). In the appeared window, find the services whose name begins with ‘Azure Pipelines Agent…’:
At this stage, we’re done with the build server configuration, but the pipeline won’t build. The fix should be implemented at the agent level. For that, go to the project settings in Azure DevOps -> Agent pools -> find the agent pool in question to see the agents installed on the build server (I have two):
Select an agent and go to the ‘Capabilities’ tab:
Just like the error message says, the ‘java’ variable is missing. Add it and point to the same locations as %JAVA_HOME% above. After that, the pipeline will execute successfully. Repeat the same for other agents if you have multiple, like me.
Hope that helps guys. Leave your comments below, subscribe to the mailing list, and stay tuned!