Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-56854

ENV GIT_COMMIT is not match the right revision occasionally when using Jenkinsfile in GitHub

XMLWordPrintable

      Problem Abstract

      env GIT_COMMIT is not always same the real git revision in particular situation.

      Before pipeline stage begin, two merge commits generated by plugins.

      It is the reason why the revision doesn't match GIT_COMMIT.

       

      GIT_COMMIT, SHA of the current, is defined by Git Plugin.

      Problem Detail

      I use GitHub Branch Source Plugin to run Pull Request job with Jenkinsfile.

      My job use Jenkinsfile in my github repository.

      I found GIT_COMMIT is sometime different from real git revision in the stage of Pipeline.

       

      When the problem happen, Jenkisn build logs says it causes git merge twice.

      First merge is to read Jenkinsfile from git, second merge is to setup working directory.

      So I print the revision in my Pipeline script.

      env.GIT_COMMIT = 75ddc1933fd10b87c529536e3107ea7313debaea
      HEAD revision = a98b709283bd47d251dfcc9360b91ffc024af16b

      GIT_COMMIT is the revision at first merge, and HEAD is the revision at second merge.

      How to reproduce this problem

      I test with minimum condition which can reproduce the problem by using it↓

      https://github.com/mtgto/jenkins-pipeline-test/blob/prtest/Jenkinsfile

      https://github.com/mtgto/jenkins-pipeline-test/pull/1

       

      The problem is only happened below all conditions matched:

      1. The job is Multibranch job.
      2. The job uses pipeline with Jenkinsfile in git repository.
      3. The pull request can't merge fast-forward.
      4. Two merge commits is away at least one second.

      1, 2: The condition to generate twice merge commits.

      3: Fast-forward merge doesn't change the revision by time.

      4: First commit is created at fetching Jenkinsfile. Second commit is created at fetching whole target repository. Git object contains time, it is changed by the second. Same time merge commits always have same revisions.

      Environments

      I use Jenkins 2.164.1 in Docker container to reproduce this problem.

      $ docker run -d --name jenkins -p 8080:8080 --name jenkins -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts-alpine

      I install two plugins while first setup:

      Installed Plugins
      • Apache HttpComponents Client 4.x API Plugin - 4.5.5-3.0
      • Authentication Tokens API Plugin - 1.3
      • bouncycastle API Plugin - 2.17
      • Branch API Plugin - 2.2.0
      • Command Agent Launcher Plugin - 1.3
      • Credentials Binding Plugin - 1.18
      • Credentials Plugin - 2.1.18
      • Display URL API - 2.3.1
      • Docker Commons Plugin - 1.13
      • Docker Pipeline - 1.17
      • Durable Task Plugin - 1.29
      • Folders Plugin - 6.7
      • Git client plugin - 2.7.6
      • Git plugin - 3.9.3
      • GIT server Plugin - 1.7
      • GitHub API Plugin - 1.95
      • GitHub Branch Source Plugin - 2.4.5
      • GitHub plugin - 1.29.4
      • Jackson 2 API Plugin - 2.9.8
      • JavaScript GUI Lib: ACE Editor bundle plugin - 1.1
      • JavaScript GUI Lib: Handlebars bundle plugin - 1.1.1
      • JavaScript GUI Lib: jQuery bundles (jQuery and jQuery UI) plugin - 1.2.1
      • JavaScript GUI Lib: Moment.js bundle plugin - 1.1.1
      • JDK Tool Plugin - 1.2
      • JSch dependency plugin - 0.1.55
      • JUnit Plugin - 1.27
      • Lockable Resources plugin - 2.5
      • Mailer Plugin - 1.23
      • Matrix Project Plugin - 1.14
      • Pipeline - 2.6
      • Pipeline Graph Analysis Plugin - 1.9
      • Pipeline: API - 2.33
      • Pipeline: Basic Steps - 2.15
      • Pipeline: Build Step - 2.8
      • Pipeline: Declarative - 1.3.7
      • Pipeline: Declarative Agent API - 1.1.1
      • Pipeline: Declarative Extension Points API - 1.3.7
      • Pipeline: Groovy - 2.65
      • Pipeline: Input Step - 2.10
      • Pipeline: Job - 2.32
      • Pipeline: Milestone Step - 1.3.1
      • Pipeline: Model API - 1.3.7
      • Pipeline: Multibranch - 2.21
      • Pipeline: Nodes and Processes - 2.29
      • Pipeline: REST API Plugin - 2.10
      • Pipeline: SCM Step - 2.7
      • Pipeline: Shared Groovy Libraries - 2.13
      • Pipeline: Stage Step - 2.3
      • Pipeline: Stage Tags Metadata - 1.3.7
      • Pipeline: Stage View Plugin - 2.10
      • Pipeline: Step API - 2.19
      • Pipeline: Supporting APIs - 3.2
      • Plain Credentials Plugin - 1.5
      • SCM API Plugin - 2.4.0
      • Script Security Plugin - 1.56
      • SSH Credentials Plugin - 1.15
      • Structs Plugin - 1.17
      • Token Macro Plugin - 2.7

            Unassigned Unassigned
            mtgto Satoshi Goto
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: