[英]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.