title | description | ms.topic | ms.date | monikerRange |
---|---|---|---|---|
Publish Maven artifacts |
How to publish Maven artifacts with Azure Pipelines |
conceptual |
10/24/2022 |
<= azure-devops |
Using Azure Pipelines, you can publish your Maven packages to Azure Artifacts feeds, public registries, or as a pipeline artifact.
-
Add the following snippet to the
repositories
anddistributionManagement
sections in your pom.xml file. Replace the placeholders with your organization name, project name, and your feed name.<repository> <id>MavenDemo</id> <url>https://pkgs.dev.azure.com/ORGANIZATION-NAME/PROJECT-NAME/_packaging/FEED-NAME/maven/v1</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository>
-
Configure your settings.xml file as follows. Replace the placeholders with your organization name, your project name, and your personal access token.
<server> <id>PROJECT-NAME</id> <username>ORGANIZATION-NAME</username> <password>PERSONAL-ACCESS-TOKEN</password> </server>
-
Create a Personal Access Token with Packaging read & write scope and paste it into the
password
tag in your settings.xml file.
In this example, we're using the Maven task to build the project with Azure Pipelines.
- task: Maven@3
inputs:
mavenPomFile: 'my-app/pom.xml' // Path to your pom file
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'package'
The following example illustrates how to publish your artifact to drop in your pipeline. Use the Copy files task to copy your packages to a target folder, then use Publish Build Artifacts to publish your build artifacts to Azure Pipelines.
- task: CopyFiles@2
inputs:
Contents: '**'
TargetFolder: '$(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
:::image type="content" source="media/published-maven-pipeline.png" alt-text="A screenshot showing the build artifact published to drop in Azure Pipelines.":::
To publish your package to an Azure Artifacts feed, use the Maven task to deploy your artifact to your feed.
- task: Maven@3
inputs:
mavenPomFile: 'my-app/pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
mavenAuthenticateFeed: true
publishJUnitResults: false
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'deploy'
:::image type="content" source="media/maven-published-to-feed.png" alt-text="A screenshot showing the build artifact published to a feed.":::
A: You can use the MavenAuthenticate task to authenticate with Maven feeds inside and outside your organization. See the examples below for more details: