从另一个分支上的另一个仓库构建一个 Jenkins 管道(工作)

Build a Jenkins pipeline (job) from another repo on another branch

我想做的事情看起来不那么复杂但也不那么容易,但是我现在读到的东西看起来像是在发射火箭。

基本上假设我有

my-deploys-repo with branches: master, develop
my-tools-repo with whatever branches
Inside my-tools-repo I have: Jenkinsfile-push-events ( jenkins pipeline )
Inside my-deploys-repo I have ON DEVELOP BRANCH: Jenkinsfile-deploy (which also gets some params, if it matters )

如何从 my-deploys-repo 的开发分支 FROM Jenkinsfile-push-events on my-tools-repo 触发 Jenkinsfile-deploy 作业?

我知道通常我会做类似的事情(在 Jenkinsfile-push-events 中)

        stage('Deploy') {
            steps {
                script {
                    build job: '../my-deploys-repo/Jenkinsfile-deploy'   
                }
            }

但它放在另一个分支上似乎是个问题。

Jenkins 中的作业在其属性中有其定义,并且已经包含 Jenkinsfile,因此如果不定义首先使用该 Jenkinsfile 的作业,您将无法触发“Jenkinsfile”。

如果您有两个分支,则需要一个多分支管道作业。

假设您创建了一个新的 Multibranch Pipeline 作业——假设 MyJob 是它的名称——配置为使用您的存储库 (my-deploys-repo.git) 和您的 Jenkinsfile 路径 (Jenkinsfile-deploy.groovy ).然后您可以通过以下方式触发该作业:

build job: "MyJob/develop", wait: false, propagate: false,
    parameters: [
         string(name: 'PARAM_1', value: "1"),
         string(name: 'PARAM_2', value: "maybe"), //etc.
   ]