簡體   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