繁体   English   中英

Jenkins Artifactory 插件与 Maven

[英]Jenkins Artifactory Plugin vs. Maven

几个问题:

  1. 在凭据和插件的授权方面,我是否缺少一些明显的东西?
  2. 为什么 pom 文件上的上传失败,而不是实际的工件?
  3. 使用 Jenkins Artifactory 插件而不是仅使用 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 有三个主要优点。

  1. 并行 maven 部署- 我们最近发布了这篇博客文章,讨论了这一优势。

  2. 安全性 - 使用 Artifactory 管道 API 时,您可以在 Jenkins 中管理凭据,而不是将它们存储在settings.xml 中或作为环境变量。 Jenkins 为您处理凭证加密和管理。

  3. 更好的控制- 使用 Artifactory 管道 API,您不再需要在settings.xmlpom.xml中管理 Artifactory 服务器 URL 和存储库。 您可以从管道脚本中完全控制构建的分辨率和部署目标。 您可以在此处阅读有关此内容的更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM