Jenkins Artifactory 插件与 Maven
Jenkins Artifactory Plugin vs. Maven
几个问题:
- 在凭据和插件的授权方面,我是否明显遗漏了什么?
- 为什么 pom 文件上传失败而不是实际工件?
- 使用 Jenkins Artifactory 插件而不是仅使用 Maven 命令的优势是什么?
我一直在尝试使用 Jenkins Artifactory 插件配置 Jenkins 管道。当到达包含 rtMavenRun 的步骤时,我将 运行ning 保持在来自 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.xml 上失败了。所以显而易见的答案似乎是用户无权上传某些东西。 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 points out, the solution is to use the "install" goal, and not the "deploy" goal. Which, if I'd properly read the example,我早就看过了。
这个答案重点介绍了使用 Artifactory 管道 API 与直接调用 maven 的优势(关于 401 响应的另一个问题已在此处得到解答)。
使用 Artifactory 管道 API 具有三个主要优点。
几个问题:
- 在凭据和插件的授权方面,我是否明显遗漏了什么?
- 为什么 pom 文件上传失败而不是实际工件?
- 使用 Jenkins Artifactory 插件而不是仅使用 Maven 命令的优势是什么?
我一直在尝试使用 Jenkins Artifactory 插件配置 Jenkins 管道。当到达包含 rtMavenRun 的步骤时,我将 运行ning 保持在来自 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.xml 上失败了。所以显而易见的答案似乎是用户无权上传某些东西。 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 points out, the solution is to use the "install" goal, and not the "deploy" goal. Which, if I'd properly read the example,我早就看过了。
这个答案重点介绍了使用 Artifactory 管道 API 与直接调用 maven 的优势(关于 401 响应的另一个问题已在此处得到解答)。 使用 Artifactory 管道 API 具有三个主要优点。