从12.0.1升级到12.1.17后,Gitlab checkout.groovy失败

wwodge7n  于 2022-11-01  发布在  Git
关注(0)|答案(1)|浏览(124)

在Jenkins中我有一个分析作业。这个作业用于 checkout 并构建发送到目标分支的合并请求。但是,在将gitlab版本从12. 0. 1升级到12. 1. 17后,我无法 checkout 源分支。
下面是我使用的groovy脚本。


# !/usr/bin/env groovy

def call() {
    if (env.gitlabMergeRequestId) {
        sh "echo '${env.gitlabMergeRequestId}'"
        sh "echo 'Merge request detected. Merging...'"
        def credentialsId = scm.userRemoteConfigs[0].credentialsId
        checkout ([
            $class: 'GitSCM',
            branches: [[name: "${env.gitlabSourceNamespace}/${env.gitlabSourceBranch}"]],
            extensions: [
                [$class: 'PruneStaleBranch'],
                [$class: 'CleanCheckout'],
                [
                    $class: 'PreBuildMerge',
                    options: [
                        fastForwardMode: 'NO_FF',
                        mergeRemote: env.gitlabTargetNamespace,
                        mergeTarget: env.gitlabTargetBranch
                    ]
                ]
            ],
            userRemoteConfigs: [
                [
                    credentialsId: credentialsId,
                    name: env.gitlabTargetNamespace,
                    url: env.gitlabTargetRepoHttpURL
                ],
                [
                    credentialsId: credentialsId,
                    name: env.gitlabSourceNamespace,
                    url: env.gitlabSourceRepoHttpURL
                ]
            ]
        ])
    } else {
        sh "echo 'No merge request detected. Checking out current branch'"
        checkout ([
            $class: 'GitSCM',
            branches: scm.branches,
            extensions: [
                    [$class: 'PruneStaleBranch'],
                    [$class: 'CleanCheckout']
            ],
            userRemoteConfigs: scm.userRemoteConfigs
        ])
    }
}

相关问题