Amending the Azure DevOps Pipeline to Use Maven with Multiple Java Versions
We are configuring the (AKS Linux) agent to support both Java 17 and Java 21 by setting appropriate environment variables. Specifically, we are defining the JAVA_HOME_17_X64 and JAVA_HOME_21_X64 environment variables on the agent. When using the Maven build task in an Azure DevOps pipeline, and selecting the Java version (e.g., 1.17) in the task configuration, the Maven task looks for a corresponding environment variable like JAVA_HOME_17_X64 on the agent. This allows the task to bind to the correct JDK version. If this environment variable is not correctly set or recognized, the task will fail to bind to the specified Java version and the pipeline will fail. If it is set correctly, the Maven task should use the specified Java version (e.g., Java 17) rather than the default one, and it should output the correct Java version during the build. In summary, proper configuration of these environment variables on the agent ensures that the Maven task selects and uses the correct Java version as specified in the task settings.
so that we can seamlessly swap in future.
Below is the screenshot from agent pool regarding env varibales:
I have use below pipeline :
YAMLCopy
trigger:
error from logs:
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.
##[debug]Process exited with code 1 and signal null for tool '/AzDOAgents/apache-maven-3.8.8/bin/mvn'
##[debug]STDIO streams have closed and received exit code 1 and signal null for tool '/AzDOAgents/apache-maven-3.8.8/bin/mvn'
##[debug]task result: Failed
##[error]Build failed.
##[debug]Processed: ##vso[task.issue type=error;source=TaskInternal;correlationId=420bf39b-8b04-4080-8535-ef817feb12f2;]Build failed.
##[debug]Processed: ##vso[task.complete result=Failed;]Build failed.
##[error]Exit code 1 returned from process: file name '/azp/externals/node20_1/bin/node', arguments '"/azp/_work/_tasks/Maven_ac4ee482-65da-4485-a532-7b085873e532/4.249.6/maventask.js"'.
when we select below version above pipeline should not fail, Please suggest further , thank you for the support.