Edit

Share via


Publish Maven artifacts with Azure Pipelines (YAML/Classic)

Azure DevOps Services | Azure DevOps Server 2022 | Azure DevOps Server 2020

Azure Pipelines enables developers to publish Maven artifacts to Azure Artifacts feeds within the same organization, across other organizations, and to public registries such as Maven Central. This article guides you through publishing your Maven artifacts using both YAML and Classic pipelines.

Prerequisites

Product Requirements
Azure DevOps - An Azure DevOps organization and a project.
- An Azure Artifacts feed.
- A working pipeline.
- Permissions:
    - To grant access to all pipelines in the project, you must be a member of the Project Administrators group.
    - To create service connections, you must have the Administrator or Creator role for service connections.

Publish packages to a feed in the same organization

  1. Sign in to your Azure DevOps organization, and then navigate to your project.
  1. Sign in to your Azure DevOps collection, and then navigate to your project.
  1. Select Pipelines, and then select your pipeline definition.
  1. 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'
    

Note

To publish packages to a feed using Azure Pipelines, make sure that both the Project Collection Build Service and your project's Build Service identities are assigned the Feed Publisher (Contributor) role in your feed settings. See Manage permissions for more details.

Publish packages to a feed in a different organization

To publish packages to a feed in a different Azure DevOps organization, you must first create a personal access token (PAT) in the target organization, and then use that PAT to create a service connection and authenticate with the target feed.

Create a personal access token

  1. Navigate to the organization that hosts the target feed.

  2. Create a personal access token with Packaging > Read & write scope.

  3. Copy your personal access token as you'll need it in the following section.

Create a service connection

  1. Sign in to the Azure DevOps organization where your pipeline will run, and then navigate to your project.

  2. Navigate to your Project settings > Service connections.

  3. Select New service connection, select Maven, and then select Next.

  4. For Authentication method, select Username and Password. Enter your Repository URL and your Repository Id.

  5. In the Username field, enter any string value (this is required, but Azure Pipelines will use your pom.xml configuration and the personal access token you created earlier for authentication).

    • For Password, paste the personal access token you created earlier.
    • Provide a Name for your service connection.
    • Check the Grant access permission to all pipelines checkbox.
  6. Select Save when you're done.

Publish packages

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Pipelines, and then select your pipeline definition.

  3. 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'