如何在构建多分支管道之前进行合并?

How to merge before build in a multi-branch pipeline?

对于简单的管道作业,我在其他行为下有 "merge before build"。但是我如何在多分支管道中做到这一点?找不到该选项。

提前致谢。

我将post这里是我通过代码所做的:

def mergeBeforeBuild() {

  // Pull the source and test a merge
  try {
    def sourceScmCheck = checkout changelog: true, poll: true, scm: [
      $class: 'GitSCM',
      branches: [[name: "origin/$sourceBranch" ]],
      doGenerateSubmoduleConfigurations: false,
      extensions: [[
        $class: 'PreBuildMerge',
        options: [
          fastForwardMode: 'FF',
          mergeRemote: 'origin',
          mergeStrategy: 'default',
          mergeTarget: "${env.target_branch}"]],
        [$class: 'UserIdentity',
          email: 'jenkins@jenkins.com',
          name: 'jenkins'
      ]],
      submoduleCfg: [],
      userRemoteConfigs: [[
        credentialsId: 'githubCredentials',
        name: 'origin',
        url: "$repoUrl"
      ]]
    ]
  } catch (error) {
    currentBuild.result = 'FAILURE'
    echo "ERROR: ${error}"
    sh 'false'
  }
}