Search code examples
azure-devopsazure-artifacts

How to connect/ authenticate a azure devops pipeline to artifacts


I am able to "deploy" from my local machine to Azure Artifacts using this documentation or this. In first link it tells to just change goal from package to deploy in the pipeline. The problem is that the pipeline

trigger:
  branches:
    include:
      - '*'

pool:
  vmImage: ubuntu-latest

steps:
- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    mavenOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.17'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    goals: 'deploy'

is failing with 401, because the server settings are missing with the credentials.

How it is supposed to work from devops pipeline? I would like to not use a personal account. But i can create a token for my account but where to put? where to change/ put settings.xml?


Solution

  • I think you need the task MavenAuthenticate@0 to provide credentials for Azure Artifacts feeds and external Maven repositories.

    trigger:
    - none
    
    pool:
      vmImage: ubuntu-latest
    
    steps:
    - task: MavenAuthenticate@0
      inputs:
        artifactsFeeds: 'xxx'
    - task: Maven@3
      inputs:
        mavenPomFile: 'demo/pom.xml'
        publishJUnitResults: true
        testResultsFiles: '**/surefire-reports/TEST-*.xml'
        javaHomeOption: 'JDKVersion'
        jdkVersionOption: '1.8'
        mavenVersionOption: 'Default'
        mavenOptions: '-Xmx3072m'
        mavenAuthenticateFeed: true
        effectivePomSkip: false
        sonarQubeRunAnalysis: false
    

    And then make sure the service account of the pipeline has permission:

    Authorization Scope

    enter image description here