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'
          }
        }
    }
}

你可能感兴趣的:(jenkins,docker,运维)