通过 Azure Pipeline 将 Maven 构建部署到 Azure Artifacts 时如何修复 401?
How to fix 401 when deploying Maven build to Azure Artifacts via Azure Pipeline?
我在 Azure Artifacts (azure-maven) 中创建了提要,添加了 MavenAuthenticate 任务以构建管道(使用 artifactsFeeds: azure-mave),添加了 mavenAuthenticateFeed: true 到 Maven 任务,将存储库添加到pom.xml 具有相同的 ID,但部署 Maven 任务失败并显示 401(未授权)。
有没有漏掉的步骤?
(如果我没有 PAT,我也不想使用,这不是使用 MavenAuthenticate 任务的原因吗?)
干杯,
史蒂夫
嗯,看起来问题实际上是将 mavenAuthenticateFeed 设置为 true,这对我来说没有意义:(
这是工作 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'
如果您自己提供 settings.xml:
<servers>
<server>
<id>azure-maven</id>
<username>AzureDevOps</username>
<password>${env.SYSTEM_ACCESSTOKEN}</password>
</server>
</servers>
您需要设置 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
我在 Azure Artifacts (azure-maven) 中创建了提要,添加了 MavenAuthenticate 任务以构建管道(使用 artifactsFeeds: azure-mave),添加了 mavenAuthenticateFeed: true 到 Maven 任务,将存储库添加到pom.xml 具有相同的 ID,但部署 Maven 任务失败并显示 401(未授权)。
有没有漏掉的步骤?
(如果我没有 PAT,我也不想使用,这不是使用 MavenAuthenticate 任务的原因吗?)
干杯, 史蒂夫
嗯,看起来问题实际上是将 mavenAuthenticateFeed 设置为 true,这对我来说没有意义:(
这是工作 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'
如果您自己提供 settings.xml:
<servers>
<server>
<id>azure-maven</id>
<username>AzureDevOps</username>
<password>${env.SYSTEM_ACCESSTOKEN}</password>
</server>
</servers>
您需要设置 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