1

我正在为我的项目运行 jenkins 管道。Jenkins 从 gitlab 中提取存储库,然后运行我的管道。所以问题是当管道成功运行时我想在gitlab上将B合并到A。这是我的 Jenkinsfile,它当然不能满足我的需要,因为它给了我错误

合并:测试 - 不是我们可以合并的东西

node {
try{
stage('Build'){
    def mavenHome  = tool 'Maven'
    checkout scm
    sh "mvn clean install"
}
stage('SonarQube') {
        steps {
            sh "mvn clean verify sonar:sonar -Dsonar.branch.name="+ env.BRANCH_NAME
        }
    }

stage('Merge with Dev') {

    sh "git checkout dev"
    sh "git pull gitlab dev"
    sh "git merge test"

    }



} catch(error){
    currentBuild.result = "FAILED"
    mail to: 'mail here',
    subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
    body: "Something is wrong with ${env.BUILD_URL}"
}
}

我想自动合并,没有合并请求。谢谢

4

1 回答 1

0

I found a way to create a merge request when the pipeline is successful and that's by using API.Well, it doesn't do exactly do what i want (directly merge the branch when possible) but it's good enough for now (automatically create a merge request in gitlab). This is the final stage in jenkinsfile

    stage('Merge with Dev') {


     sh 'curl --request POST --header "PRIVATE-TOKEN: APITOKENHERE" "GITURL/api/v4/projects/PROJECTID/merge_requests?source_branch='+env.BRANCH_NAME+'&target_branch=A&title='+env.BRANCH_NAME+'ToA"'


    }
于 2018-09-01T18:24:02.347 回答