title: Jenkins job after merge request is created
body: <p>I am using Gitlab for source control and Jenkins for build management.</p>
  
  <p>I want to create a job in Jenkins that will run after a merge request is created. It is currently failing due to:</p>
  
  <blockquote>
    <p>ERROR: Branch not suitable for integration as it does not merge cleanly: Command "git merge --ff a83f5745ba2ca0586as4cfdb7d5e207a911d34" returned status code 128:</p>
    
    <p>stdout: </p>
    
    <p>stderr: </p>
    
    <p>*** Please tell me who you are.</p>
  </blockquote>
  
  <p>In Jenkins job configuration (Which is Pipeline) I have the following:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>In my Jenkins file, I have the following related section:</p>
  
  <pre><code>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'
              }
          }
  </code></pre>
  
  <p>Happy to provide any other info if needed!</p>