![](/img/trans.png)
[英]Jenkins MultiBranch - Reference git repo's tag from pipeline file (Jenkinsfile)
[英]Jenkins: Building a Multibranch Pipeline with a jenkinsfile from another repo
所以我正在尝试为几个不同的项目制作一个多分支管道。
这些是基本要求:
所以这些要求非常简单。
但是还有第四个要求。 我想弄清楚的是,我是否可以拥有一个可以保存我所有 jenkinsfiles 的 repo,然后构建另一个 repo 的所有分支。 这可能吗? 所有其他答案似乎都指向已弃用的解决方案,例如自由式 Multibranch 项目。
是否可以使用来自另一个 repo 的 jenkinsfile 构建多分支管道?
简短回答:不,不是,因为 Multibranch Pipeline 中的每个 Job 总是从它配置为监视的同一分支(因此,来自同一个 repo)引用 Jenkinsfile。 并且不包含 Jenkinsfile 的分支不被索引。
扩展答案:为了或多或少地实现您的要求,我将执行以下操作:
Jenkinsfiles
创建一个 repo(每个分支、每个客户端、每个环境......等等)。 每个Jenkinsfile
将描述您要在每个特定情况下执行的阶段。 使用 脚本化流水线语法。Jenkinfile
添加到您的产品存储库,您可以在其中:使用自定义管道签出专用存储库,加载管道并执行它。 例子
git@github.com:your-org/custom-pipelines.git/Jenkinsfile-dev
// Jenkinsfile-dev
def stages() {
stage ("Checkout") {
checkout scm
}
stage ("Build") {
}
stage ("Test") {
}
}
return this
git@github.com:your-org/product-repo.git/Jenkinsfile
// Jenkinsfile
node ("ubuntu") {
// Checkout custom Jenkinsfiles
stage ("Checkout pipelines") {
git url: "git@github.com:your-org/custom-pipelines.git",
branch: "master",
credentialsId: "github-ssh"
}
load ("Jenkinsfile-${env.BRANCH_NAME}").stages()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.