首页 > 解决方案 > 如何在 Jenkinsfile 中将构建部署到不同的 Artifactory?

问题描述

我有一个 Jenkinsfile,我希望能够根据构建将 maven 构建部署到不同的工件。例如,如果在我将代码推送到开发分支时触发了 Jenkinsfile,我想将构建从开发分支部署到“maven-dev”工件。我有 4 个 Git 分支(dev、preprod、stage、prod)和随后的 4 个不同的 Artifactory 位置(maven-dev、maven-preprod、maven-stage、maven-prod)。

我的 Jenkinsfile 中有以下脚本用于构建部署,但是,我需要知道我需要对以下脚本进行哪些更改才能将每个构建(上述)部署到相应的 Artifactory 位置?

script {
 def server = Artifactory.server('artifacts')
 def rtMaven = Artifactory.newMavenBuild()
 rtMaven.deployer server: server, releaseRepo: 'maven-prod', snapshotRepo: 'maven-dev'
 def buildInfo = rtMaven.run pom: 'pom.xml', goals: 'clean install -DskipTests=true -q -Dartifactory.publish.buildInfo=true'
 buildInfo = Artifactory.newBuildInfo()
 server.publishBuildInfo buildInfo
}

标签: jenkins-pipelineartifactoryjfrog-mission-control

解决方案


您应该将所有 Artifactory 服务器配置放在“rtServer”块中。这为此构建定义了一个新的 Artifactory 服务器,您可以通过在“def server = Artifactory.server('NAME')”行中配置不同的名称来在不同的构建中配置不同的 Artifactory 实例,并为其提供正确的配置(存储库名称、路径等)。您可以查看此链接以获取更多信息 - https://www.jfrog.com/confluence/display/RTF/Declarative+Pipeline+Syntax#DeclarativePipelineSyntax-CreatinganArtifactoryServerInstance


推荐阅读