创建合并请求后的Jenkins作业

时间:2018-03-15 09:58:39

标签: git jenkins gitlab jenkins-pipeline

我正在使用Gitlab进行源代码管理,使用Jenkins进行构建管理。

我想在Jenkins中创建一个在创建合并请求后运行的作业。它目前因以下原因失败:

  

错误:分支不适合集成,因为它没有干净地合并:命令" git merge --ff a83f5745ba2ca0586as4cfdb7d5e207a911d34"返回状态码128:

     

stdout:

     

stderr:

     

***请告诉我你是谁。

在Jenkins作业配置(管道)中,我有以下内容:

Build Triggers
  Build when a change is pushed to GitLab. GitLab CI Service URL: http://...

  (*)Opened Merge Request Events    
  (*)Rebuild open Merge Requests: On push to source or target branch

Pipeline
  Pipeline script from SCM
    SCM: Git
      Repositories
        Repository URL: http://...
        Credentials: Jenkins
        Repository URL: ${gitlabSourceRepoSshUrl}
        Credentials: Jenkins
      Branches to build
        Branch Specifier (blank for 'any'): origin/${gitlabSourceBranch}
        Branch Specifier (blank for 'any'): merge-requests/${gitlabMergeRequestIid}
  Additional Behaviours
    (*)Wipe out repository and force clone
    (*)Merge before build
        Name of repository: origin
        Branch to merge: ${gitlabTargetBranch}
        Merge strategy: default
        Fast-forward mode: --ff

  Script Path: Jenkinsfile

在我的Jenkins文件中,我有以下相关部分:

stages {
        stage('Test') {
            steps {
                script {
                    env.isMergeRequest = env.gitlabTargetBranch != env.gitlabSourceBranch

                    deleteDir()
                    unstash 'src'

                    def javaHome = tool 'Java8'
                    def mvnHome = tool 'Maven3'
                }

                catchError {
                    withEnv(["PATH+JDK=$javaHome/bin:$mvnHome/bin", "JAVA_HOME=$javaHome"]) {
                        echo "branchName: ${env.branchName}; isMergeRequest: ${env.isMergeRequest}"
                        script {
                            if ((env.isMergeRequest != 'true')) {
                                echo "Executing tests for merge request..."
                                sh "./gradlew -Ddocker.local=true test"
                            }
                        }
                    }
                }

                fileOperations([fileZipOperation('dockerLogs')])

                archiveArtifacts allowEmptyArchive: true, artifacts: 'dockerLogs.zip'

                echo "Gathering test reports"

                junit healthScaleFactor: 10.0, testResults: '**/build/test-results/test/*.xml'
            }
        }

如果需要,很高兴提供任何其他信息!

1 个答案:

答案 0 :(得分:0)

我认为您的Git配置缺少user.name和/或user.email。也许,尝试在全球,本地或临时设置这些。

全局:

git config --global user.name 'Foo Bar'
git config --global user.email foo@bar.baz

本地(仅适用于当前的回购):

git config user.name 'Foo Bar'
git config user.email foo@bar.baz

暂时(仅适用于当前的运行 - 不确定这适用于Jenkins):

git -c user.name='Foo Bar' <command>
git -c user.email=foo@bar.baz <command>