【问题标题】:Jenkins Artifactory Plugin vs. MavenJenkins Artifactory 插件与 Maven
【发布时间】:2020-04-09 05:36:36
【问题描述】:

几个问题:

  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.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'
            }
        }
    }
}

【问题讨论】:

  • 您能否尝试将目标从“干净包部署”更改为“干净安装”?出于优化的原因,Artifactory Plugin 使用了自己的部署方式,这与 maven 的默认部署插件不同。它与“安装”目标挂钩。如果它解决了问题,请告诉我。完成后,我将添加一个答案,描述 Artifactory 插件在 maven 方面添加的优势。
  • 那行得通。我不明白为什么部署目标会导致 Artifactory 出现 401。但它工作得很好,我猜。谢谢。

标签: jenkins jenkins-pipeline artifactory


【解决方案1】:

此答案侧重于使用 Artifactory 管道 API 与直接调用 maven 相比的优势(关于 401 响应的其他问题已在此处回答)。 使用 Artifactory 管道 API 具有三个主要优势。

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

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

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

【讨论】:

    【解决方案2】:

    正如Eyal Ben Moshe 指出的那样,解决方案是使用“安装”目标,而不是“部署”目标。如果我能正确阅读example,我会看到的。

    【讨论】:

      猜你喜欢
      • 2015-04-19
      • 1970-01-01
      • 1970-01-01
      • 2014-04-21
      • 1970-01-01
      • 2015-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多