1
votes

I've created feed in Azure Artifacts (azure-maven), added the MavenAuthenticate task the to build pipeline (with artifactsFeeds: azure-mave), added mavenAuthenticateFeed: true to the Maven task, added the repository to the pom.xml with the same ID, but when deploying the Maven task fails with 401 (Unauthorized).

Is there a step I have missed?

(I dont want to use a PAT if I dont have too, isnt that the reason to use MavenAuthenticate task?)

Cheers, Steve

2

2 Answers

1
votes

Hmmm, looks like the issue was actually setting mavenAuthenticateFeed to true, which doesnt make sense to me :(

Here is the working yml:

trigger:
- main

variables:
  - name: MAVEN_CACHE_FOLDER
    value: $(Pipeline.Workspace)/.m2/repository
  - name: MAVEN_OPTS
    value: -Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: MavenAuthenticate@0
  inputs:
    artifactsFeeds: 'azure-maven'

- task: Cache@2
  inputs:
    key: 'maven | "$(Agent.OS)" | pom.xml'
    path: '$(MAVEN_CACHE_FOLDER)'
    cacheHitVar: 'CacheRestored'
    restoreKeys: |
      maven | "$(Agent.OS)"
      maven
  displayName: Cache Maven local repo

- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    goals: 'package deploy'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    javaHomeOption: 'JDKVersion'
    mavenVersionOption: 'Default'
    mavenOptions: '-Xmx3072m $(MAVEN_OPTS)'
    mavenAuthenticateFeed: false
    jdkVersionOption: '1.8'
    jdkArchitectureOption: 'x64'
    effectivePomSkip: false
    sonarQubeRunAnalysis: false

- task: CopyFiles@2
  inputs:
    Contents: '**/target/*.jar'
    TargetFolder: '$(Build.ArtifactStagingDirectory)'
    CleanTargetFolder: true
    flattenFolders: true

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'Test'
    publishLocation: 'Container'
1
votes

And if supplying your own settings.xml:

  <servers>
    <server>
      <id>azure-maven</id>
      <username>AzureDevOps</username>
      <password>${env.SYSTEM_ACCESSTOKEN}</password>
    </server>
  </servers>

You need to set up the SYSTEM_ACCESSTOKEN:

- task: DownloadSecureFile@1
  name: mvnSettings
  inputs:
    secureFile: 'settings.xml'
- task: Maven@3
  env:
    SYSTEM_ACCESSTOKEN: $(System.AccessToken)
  inputs:
    mavenPomFile: 'pom.xml'
    goals: 'clean deploy'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    javaHomeOption: 'JDKVersion'
    mavenVersionOption: 'Default'
    options: '-s $(mvnSettings.secureFilePath)'
    mavenOptions: '-Xmx3072m $(MAVEN_OPTS)'
    mavenAuthenticateFeed: false
    jdkVersionOption: '1.8'
    jdkArchitectureOption: 'x64'
    effectivePomSkip: false
    sonarQubeRunAnalysis: false