Jenkins基于MergeRequest进行预合并编译



pipeline {
    agent {
  
  stages {
      // 拉取代码
      stage('拉取代码') {
        steps {
          echo 'checkouting code'
          echo "${user_name}"
          echo '###'
          echo "${env.gitlabUserEmail}"
          echo "${env.gitlabUserName}"
          echo "${env.GIT_URL}"
          echo "${env.gitlabSourceRepoURL}"
          echo "${env.gitlabSourceRepoHttpUrl}"
          echo "${env.GIT_CREDENTIAL_ID}"
          checkout changelog: true, poll: true, scm: [
            $class: 'GitSCM',
            branches: [[name: "${env.gitlabSourceBranch}"]],
            doGenerateSubmoduleConfigurations: false,
            extensions: [[
                $class: 'PreBuildMerge',
                options: [
                  $class: 'UserMergeOptions',
                  fastForwardMode: 'FF',
                  mergeRemote: 'origin',
                  mergeStrategy: 'default',
                  mergeTarget: "${env.gitlabTargetBranch}"
                ]
              ], [
                $class: 'LocalBranch', 
                localBranch: 'master'
              ], [
                $class: 'UserIdentity', 
                email: "${env.gitlabUserEmail}", 
                name: "${env.gitlabUserName}"
              ]
            ],
            submoduleCfg: [],
            userRemoteConfigs: [[
              refspec: "+refs/merge-requests/${env.gitlabMergeRequestIid}/head:refs/remotes/origin/mr/${env.gitlabMergeRequestIid}",
              credentialsId: "${env.GIT_CREDENTIAL_ID}",
              url: "${env.gitlabSourceRepoHttpUrl}"
            ]]
          ]
        }
      }
      // 单元测试和编译打包
      stage('编译打包') {
        steps {
            container('maven') {
                script{
                    tools.PrintMes("编译打包","blue")
                    build.ShellBuild("${buildShell}")
                    // manager.addShortText("${gitBranch} ${gitBranch} ${state} By ${user_name}")
                    echo "building ..."
                    updateGitlabCommitStatus name: 'build', state: 'running'
                }
            }
        }
      }
      // 接口测试
      stage('InterfaceTest') {
          steps{
              sh "cat pom.xml"
              sh "cat README.md"
              sh 'echo "接口测试"'
          }
      }
    }
    // 构建后的操作
    post {
        success {
          script {
            updateGitlabCommitStatus name: 'build', state: 'success'
          }
        }
        failure {
          script {
            updateGitlabCommitStatus name: 'build', state: 'failed'
          }
        }
        aborted {
          script {
            updateGitlabCommitStatus name: 'build', state: 'canceled'
          }
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值