Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Latest commit

 

History

History
163 lines (106 loc) · 5.88 KB

publish-maven-artifacts.md

File metadata and controls

163 lines (106 loc) · 5.88 KB
title description ms.topic ms.date monikerRange
Publish Maven artifacts
Learn how to publish Maven artifacts to internal and external feed using Azure Pipelines.
how-to
11/18/2024
<= azure-devops

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

Publish packages to a feed in the same organization

::: moniker range="azure-devops"

  1. Sign in to your Azure DevOps organization, and then navigate to your project. ::: moniker-end

::: moniker range="< azure-devops"

  1. Sign in to your Azure DevOps collection, and then navigate to your project. ::: moniker-end

::: moniker range="<=azure-devops" 2. Select Pipelines, and then select your pipeline definition. ::: moniker-end

  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'

::: moniker range="azure-devops"

  1. Sign in to your Azure DevOps organization, and then navigate to your project. ::: moniker-end

::: moniker range="< azure-devops"

  1. Sign in to your Azure DevOps collection, and then navigate to your project. ::: moniker-end

::: moniker range="<=azure-devops" 2. Select Pipelines, and then select your pipeline definition. ::: moniker-end

  1. Select Edit, and then select the + sign to add a new task. Add the Maven Authenticate and Command line tasks to your pipeline definition and configure them as follows:

    1. Maven Authenticate: Select one or multiple feeds from the Feeds dropdown menu.

    2. Command line task:

      • Display name: Publish.
      • Script:
        mvn deploy
        
  2. Select Save & queue when you're done.


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 have the Feed Publisher (Contributor) role in your feed settings. See Manage permissions for more details.

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

  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. Select Username and Password as the Authentication method, and then enter your Repository URL and your Repository Id.

  5. 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.

  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'

::: moniker range="azure-devops"

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

::: moniker-end

::: moniker range="< azure-devops"

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

::: moniker-end

::: moniker range="<=azure-devops"

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

::: moniker-end

  1. Select Edit, and then select the + sign to add a new task. Add the Maven Authenticate and Command line tasks to your pipeline definition and configure them as follows:

    1. Maven Authenticate: Select your service connection from the Credentials for repositories outside this organization/collection dropdown menu.

    2. Command line task:

      • Display name: Publish.
      • Script:
        mvn deploy
        
  2. Select Save & queue when you're done.


Related content