We have Azure Devops pipeline and Linux Based Build agent.
Installed Maven 3.9.0 on Linux Build agent and environment variable is working fine.
But when i run the Azure pipeline it picks up Maven 3.5.4.
When configure the Maven path in Azure Pipleine task, it's pickup correctly.
Tried restart the build agent.But it's not working as expected.
As environemnt variable is working fine for Maven 3.9.0. Would like to fix why Pipeline picking up apache 3.5.4 wrong version.
Yaml Pipeline:
Without custom Maven path to 3.9.0 (Pipeline picking Maven 3.5.4)
- task: Maven#3
inputs:
mavenPomFile: 'test Services/pom.xml'
options: 'clean install org.owasp:dependency-check-maven:8.0.1:aggregate'
publishJUnitResults: true
javaHomeOption: 'JDKVersion'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: true
sqMavenPluginVersionChoice: 'pom'
With custom Maven path to 3.9.0
- task: Maven#3
inputs:
mavenPomFile: 'test services/pom.xml'
options: 'clean install org.owasp:dependency-check-maven:8.0.1:aggregate'
publishJUnitResults: true
javaHomeOption: 'JDKVersion'
mavenVersionOption: 'Path'
mavenDirectory: '/opt/apache-maven-3.9.0'
mavenSetM2Home: false
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: true
sqMavenPluginVersionChoice: 'pom'
Result from where is mvn and mvn -v command. Used the account used for running the pipeline.
[test#Build01 ~]$ whereis mvn
mvn: /usr/bin/mvn /opt/apache-maven-3.9.0/bin/mvn.cmd /opt/apache-maven-3.9.0/bin/mvn /usr/share/man/man1/mvn.1.gz
[test#Build01 ~]$ mvn -v
Apache Maven 3.9.0 (9b58d2bad23a66be161c4664ef21ce219c2c8584)
Maven home: /opt/apache-maven-3.9.0
Java version: 17.0.5, vendor: Oracle Corporation, runtime: /opt/jdk-17/jdk-17.0.5
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-348.el8.x86_64", arch: "amd64", family: "unix"
[test#Build01 ~]$
Related
I need to use Java 14 on a hosted agent (macos-12) and I'm trying to install it through a script and then use the JavaToolInstaller task to make it available.
I have modified the script from https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/java-tool-installer?view=azure-devops
jobs:
- job: RunApiTests
pool:
vmImage: macOS-12
condition: ne(variables['Build.SourceBranch'], 'refs/heads/main')
steps:
- task: JavaToolInstaller#0
displayName: Install Java 14
inputs:
versionSpec: '14'
jdkArchitectureOption: 'x64'
jdkSourceOption: AzureStorage
azureResourceManagerEndpoint: {azureResourceManagerEndpoint}
azureStorageAccountName: {azureStorageAccountName}
azureContainerName: openjdk
azureCommonVirtualFile: 'openjdk-14.0.2.zip'
jdkDestinationDirectory: '$(agent.toolsDirectory)/jdk14'
cleanDestinationDirectory: false
Below is the error I am getting:
##[error]JDK file is not valid. Verify if JDK file contains only one root folder with 'bin' inside.
I downloaded the 14.0.2 (build 14.0.2+12) jdk for Mac from https://jdk.java.net/archive/ and I compressed only the Home folder to a zip file because bin is in there.
So, as per the requirement, the zip file contains only one root folder 'Home' with bin inside.
I need help on why I'm getting this error.
I tried to test your yaml in my pipeline and it works. The following are my steps.
I downloaded this package:
In my zip, I have these files:
Uploaded to the storage account.
Yaml:
trigger:
- none
pool:
vmImage: macos-12
steps:
- task: JavaToolInstaller#0
inputs:
versionSpec: '14'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'AzureStorage'
azureResourceManagerEndpoint: 'myEndpoint'
azureStorageAccountName: 'teststorage'
azureContainerName: 'test'
azureCommonVirtualFile: 'homefolder.zip'
jdkDestinationDirectory: '$(agent.toolsDirectory)/jdk14'
cleanDestinationDirectory: false
Result:
I am running my job on a specific agent and using below commands
- script: |
java -version
env:
JAVA_HOME: $(JAVA_HOME_11_X64)
PATH: $(JAVA_HOME_11_X64)/bin:$(PATH)
Output
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.18.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.18.04, mixed mode, sharing)
But when the maven command runs it doesn't find java so what exactly should I pass here. openjdk 11.0.11 is present on agent and how to pass this in maven? I tried passing 1.8 and 11.0.11 but it given error for that too. How to solve this and what exactly should I pass here in maven task?
- task: Maven#3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '11'
jdkArchitectureOption: 'x64'
Output
##[error]Unhandled: Failed to find the specified JDK version. Please ensure the specified JDK version is installed on the agent and the environment variable 'JAVA_HOME_11_X64' exists and is set to the location of a corresponding JDK or use the [Java Tool Installer](https://go.microsoft.com/fwlink/?linkid=875287) task to install the desired JDK.
Finishing: Maven
In Maven task, if you need to use JAVA 11 , you can try to set the jdkVersionOption to 1.11.
For example:
- task: Maven#3
inputs:
mavenPomFile: 'pom.xml'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
mavenVersionOption: 'Default'
From your description, JAVA 11 has been installed on your agent.
If this issue still exists, you can configure the Pipeline variable for Java 11.
You can add a Command Line task/ PowerShell task/ Bash task to run the following command.
- task: PowerShell#2
inputs:
targetType: 'inline'
script: |
echo "##vso[task.setvariable variable=JAVA_HOME]$(JAVA_HOME_11_X64)"
echo "##vso[task.setvariable variable=PATH]$(JAVA_HOME_11_X64)\bin;$(PATH)"
In this case, the java parameter will be set to the Pipeline global variable
After the 7.0 Gradle version my pipeline is crashing.
I want to downgrade it to 6.8.3. I tried with gradle wrapper --gradle-version=6.8.3 but its do nothing.
Btw its a Microsoft-hosted agent with ubuntu-latest VM.
I didn't find other solution, but it's work correctly.
- script: |
wget https://downloads.gradle-dn.com/distributions/gradle-6.8.3-bin.zip
unzip -d . gradle-6.8.3-bin.zip
displayName: Download Gradle 6.8.3
- script: |
./../../gradle-6.8.3/bin/gradle bundleRelease
displayName: Build Bundle
Please add distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip in your gradle/wrapper/gradle-wrapper.properties file.
For example:
Here is the document.
Here is my configuration of pipeline and result:
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Gradle#2
inputs:
gradleWrapperFile: 'gradlew'
tasks: 'build'
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
gradleOptions: '-Xmx3072m'
sonarQubeRunAnalysis: false
I am trying to execute the Selenium test in my self hosted VM from Azure pipelines. I am getting below error message.
##[error]Version spec 3.8 for architecture x64 did not match any version in Agent.ToolsDirectory.
Below is my Yaml
trigger:
- main
pool: default strategy: matrix:
Python38:
python.version: '3.8'
addToPath: true
steps:
- task: UsePythonVersion#0 inputs:
versionSpec: '$(python.version)'
addToPath: true
architecture: 'x64' displayName: 'Use Python $(python.version)'
- script: |
python -m pip install --upgrade pip
pip install -r requirements.txt displayName: 'Install dependencies'
- script: |
pip install pytest-azurepipelines
pytest tests\test_smoke\test_suite_SmokeTest.py -s -v --browser Chrome --html=report.html --reruns 2 displayName: 'pytest'
- task: DownloadPipelineArtifact#2 inputs:
buildType: 'specific'
project: '8801f21d-f4e9-4b65-b01e-68baf825747c'
definition: '5'
buildVersionToDownload: 'latest'
targetPath: '$(Pipeline.Workspace)'
I have configured the agent in my VM. I have also installed the python 3.8.6 in VM and configured the python path for it.
Unable to run Python Selenium Tests on Self Hosted Azure VM
To use this task on the private agent, we need to add the desired Python version to the tool cache on the self-hosted agent in order for the task to use it.
Normally the tool cache is located under the _work/_tool directory of the agent or you could use the command line task to echo the variable $(Agent.ToolsDirectory) to get the path.
Then, under that directory, create the following directory structure based off of your Python version:
$AGENT_TOOLSDIRECTORY/
Python/
{version number}/
{platform}/
{tool files}
{platform}.complete
The version number should follow the format of 1.2.3. The platform
should either be x86 or x64. The tool files should be the unzipped
Python version files. The {platform}.complete should be a 0 byte file
that looks like x86.complete or x64.complete and just signifies the
tool has been installed in the cache properly.
My test directory structure:
$AGENT_TOOLSDIRECTORY/
Python/
3.9.0/
x64/
python-3.9.0-amd64.exe
x64.complete
Now, it works fine on my Self Hosted agent:
You could refer the FAQ in this document for some more details.
I need Maven version 3.5.3 or above to build my project hosted on github. The default version for maven used in Azure pipelines CI/CD is 3.3.9.
I can see that there is a way to install a different version of java using Java tool installer. I don't find such an option in their documentation for maven.
But for maven it is possible to specify the
mavenVersionOption: 'Default' # Options: default, path
mavenDirectory: # Required when mavenVersionOption == Path
But being a newbie I don't understand how to install maven and specify a path here.
Any help on how to use a different version for my maven build in Azure pipelines CI/CD would be appreciated.
Since I am on an Ubuntu environment I was able to get this running by using a script to download maven and by setting the path for maven as follows:
pool:
vmImage: 'Ubuntu 16.04'
steps:
- script: 'wget http://www-eu.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.zip'
- task: ExtractFiles#1
inputs:
archiveFilePatterns: 'apache-maven-3.5.4-bin.zip'
destinationFolder: '$(build.sourcesdirectory)/maven'
- task: Maven#3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
goals: 'clean install -P ballerina'
mavenVersionOption: 'Path'
mavenDirectory: '$(build.sourcesdirectory)/maven/apache-maven-3.5.4'
mavenSetM2Home: true
You can find the yaml file that works for all OSes here.
Thanks #starian chen-MSFT for the heads up.
Refer to these steps:
Download maven installer package and add to source control (You can download it during build/release too)
Add Extract files task (Archive file patterns: apache-maven-3.5.4-bin.zip; Destination folder: $(build.sourcesdirectory)\maven)
Add PowerShell task:
code:
Write-Host "##vso[task.setvariable variable=M2_HOME;]$(build.sourcesdirectory)\maven\apache-maven-3.5.4"
Write-Host "##vso[task.setvariable variable=MAVEN_HOME;]$(build.sourcesdirectory)\maven\apache-maven-3.5.4"
Write-Host "##vso[task.prependpath]$(build.sourcesdirectory)\maven\apache-maven-3.5.4\bin"
Add PowerShell task to check version: mvn --version