[英]Jenkins Artifactory Plugin vs. Maven
幾個問題:
我一直在嘗試使用 Jenkins Artifactory 插件配置 Jenkins 管道。 當到達包含 rtMavenRun 的步驟時,我不斷遇到來自 Artifactory 的 401 響應。 在日志中我看到了這個:
注意:為簡潔起見,我將網址替換為
Downloading from eti-artifacts-snapshot: http://<URL>/work-queue-api/1.1.0-SNAPSHOT/maven-metadata.xml
Uploading to eti-artifacts-snapshot: http://<URL>/work-queue-api/1.1.0-SNAPSHOT/work-queue-api-1.1.0-20200407.120051-1.jar
Progress (1): 0.5/66 MB
Progress (1): 1.0/66 MB
....
Progress (1): 64/66 MB
Progress (1): 65/66 MB
Progress (1): 66/66 MB
Progress (1): 66 MB
Uploading to eti-artifacts-snapshot: http://<URL>/libs-snapshot/com/etisoftware/work-queue-api/1.1.0-SNAPSHOT/work-queue-api-1.1.0-20200407.120051-1.pom
Progress (1): 4.1/7.2 kB
Progress (1): 7.2 kB
[main] INFO org.apache.maven.cli.event.ExecutionEventLogger - ------------------------------------------------------------------------
[main] INFO org.apache.maven.cli.event.ExecutionEventLogger - BUILD FAILURE
[main] INFO org.apache.maven.cli.event.ExecutionEventLogger - ------------------------------------------------------------------------
[main] INFO org.apache.maven.cli.event.ExecutionEventLogger - Total time: 01:06 min
[main] INFO org.apache.maven.cli.event.ExecutionEventLogger - Finished at: 2020-04-07T08:00:57-04:00
[main] INFO org.apache.maven.cli.event.ExecutionEventLogger - ------------------------------------------------------------------------
[main] ERROR org.apache.maven.cli.MavenCli - Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-cli) on project work-queue-api: Failed to deploy artifacts: Could not transfer artifact work-queue-api:jar:1.1.0-20200407.120051-1 from/to eti-artifacts-snapshot (http://<URL>/libs-snapshot): Transfer failed for http://<URL>/artifactory/libs-snapshot-local/com/etisoftware/work-queue-api/1.1.0-SNAPSHOT/work-queue-api-1.1.0-20200407.120051-1.jar 401 Unauthorized -> [Help 1]
請注意,它似乎正在上傳 jar 文件,但它在 pom 上失敗。 所以顯而易見的答案似乎是用戶沒有權限上傳一些東西。 Jenkins 中的工件配置使用與我的m2/settings.xml
文件相同的憑據。 當我運行mvn clean package deploy
時,它按預期工作。
然后我將我的 Jenkinsfile 更改為直接使用 mvn 命令,它也按預期工作。 這將再次使用 settings.xml 文件。
這是使用插件時的管道。 這不起作用,我得到 401 響應。
pipeline {
agent any
stages {
stage ('Artifactory configuration') {
steps {
rtMavenDeployer (
id: "RT_MAVEN_DEPLOYER",
serverId: "ETI_ARTIFACTORY",
releaseRepo: "libs-release-local",
snapshotRepo: "libs-snapshot-local"
)
rtMavenResolver (
id: 'RT_MAVEN_RESOLVER',
serverId: 'ETI_ARTIFACTORY',
releaseRepo: 'libs-release',
snapshotRepo: 'libs-snapshot'
)
}
}
stage('Maven exec') {
steps {
rtMavenRun (
pom: 'pom.xml',
goals: 'clean package deploy',
tool: 'M2_TOOL',
resolverId: 'RT_MAVEN_RESOLVER',
deployerId: 'RT_MAVEN_DEPLOYER'
)
}
}
stage ('Publish build info') {
steps {
rtPublishBuildInfo (
serverId: "ETI_ARTIFACTORY"
)
}
}
stage('Build a Docker image and push to Artifactory'){
steps {
sh 'mvn docker:build docker:push'
}
}
}
}
這是使用 shell 命令設置的管道,這確實有效。
pipeline {
agent any
stages {
stage('Maven exec') {
steps {
sh 'mvn clean package deploy'
}
}
stage('Build a Docker image and push to Artifactory'){
steps {
sh 'mvn docker:build docker:push'
}
}
}
}
正如Eyal Ben Moshe指出的那樣,解決方案是使用“安裝”目標,而不是“部署”目標。 如果我正確閱讀了示例,我會看到的。
此答案側重於使用 Artifactory 管道 API 與直接調用 maven 相比的優勢(關於 401 響應的其他問題已在此處回答)。 使用 Artifactory 管道 API 有三個主要優點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.