Publish Maven artifacts with Azure Pipelines (YAML/Classic)
Using Azure Pipelines, you can publish your Maven artifacts to Azure Artifacts feeds in your organization, in other organizations, and to public registries such as Maven Central. This article will guide you through publishing your Maven artifacts using both YAML and Classic pipelines.
Prerequisites
An Azure DevOps organization. Create one for free.
An Azure DevOps project. Create a new project if you don't have one already.
An Azure Artifacts feed. Create one for free.
Publish packages to a feed in the same organization
- Sign in to your Azure DevOps organization, and then navigate to your project.
- Sign in to your Azure DevOps collection, and then navigate to your project.
- Select Pipelines > Builds, and then select your build definition.
- Select Pipelines, and then select your pipeline definition.
- Select Edit, and then add the following snippet to your YAML pipeline.
steps:
- task: MavenAuthenticate@0
displayName: 'Authenticate to Azure Artifacts feed'
inputs:
artifactsFeeds: 'MavenDemo,MavenDemoFeed2' ## Select one or multiple feeds to authenticate with.
- script: |
mvn deploy
displayName: 'Publish'
Publish packages to a feed in another organization
To publish your packages to a feed in another Azure DevOps organization, you must first create a personal access token in the target organization.
Navigate to the organization hosting your target feed and Create a personal access token with Packaging > Read & write scope. Copy your personal access token as you'll need it in the following section.
Create a service connection
Sign in to the Azure DevOps organization where your pipeline will run, and then navigate to your project.
Navigate to your Project settings > Service connections.
Select New service connection, select Maven, and then select Next.
Select Username and Password as the Authentication method, and then enter your Repository URL and your Repository Id.
Enter your Username (a placeholder, as Azure Pipelines will use your
pom.xml
configuration file and the personal access token you created earlier to authenticate). For Password, paste your personal access token. Provide a Name for your service connection, and check the Grant access permission to all pipelines checkbox.Select Save when you're done.
Publish packages
Sign in to your Azure DevOps organization, and then navigate to your project.
Select Pipelines, and then select your pipeline definition.
Select Edit, and then add the following snippet to your YAML pipeline.
steps:
- task: MavenAuthenticate@0
displayName: 'Authenticate to Azure Artifacts feed'
inputs:
MavenServiceConnections: <NAME_OF_YOUR_SERVICE_CONNECTION>
- script: |
mvn deploy
displayName: 'Publish'