jenkins-pipeline - 如何在 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
}
解决方案
您应该将所有 Artifactory 服务器配置放在“rtServer”块中。这为此构建定义了一个新的 Artifactory 服务器,您可以通过在“def server = Artifactory.server('NAME')”行中配置不同的名称来在不同的构建中配置不同的 Artifactory 实例,并为其提供正确的配置(存储库名称、路径等)。您可以查看此链接以获取更多信息 - https://www.jfrog.com/confluence/display/RTF/Declarative+Pipeline+Syntax#DeclarativePipelineSyntax-CreatinganArtifactoryServerInstance
推荐阅读
- r - 将 XGBoost eval_metric 交叉验证计算与权重匹配
- javascript - cors 污染图像上的映射颜色转换
- python - 需要帮助使用带括号的字符串
- keycloak - 是否可以从 Keycloak 中检索 AUTH_SESSION_ID cookie?
- r - Anova 测试 - 具有两个因素比较的单独组
- ibm-cloud - 上传后 bluemix 应用程序推送挂起
- ios - 使用 PinLayout 制作网格视图
- python - 组合 2 个列表,每次 n 个元素
- swift - 在 Swift 中,为什么错误“类型别名引用自身”取决于类型别名的定义位置?
- excel - 插入的带有单元格引用的公式无法识别新输入