Hol*_*nGs 4 git jenkins jenkins-pipeline
所以我正在尝试为几个不同的项目制作一个多分支管道。
这些是基本要求:
所以这些要求非常简单。
但是还有第四个要求。我想弄清楚的是,我是否可以拥有一个可以保存我所有 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
Run Code Online (Sandbox Code Playgroud)
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()
}
Run Code Online (Sandbox Code Playgroud)