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

GIT_BRANCH set to detached when sha1 parameter set in notifyCommit URL

    XMLWordPrintable

Details

    Description

      We recently upgraded our stash install including the stash jenkins webhook. Now this plugin has recently started calling the Jenkins git notifyCommit endpoint with branches and sha1 query string parameters set in the URL, e.g. it now calls URLs like

      /jenkins/git/notifyCommit?url=ssh%3A%2F%2Fgit%40my-stash-host%3A7999%2Fproject%2Frepository.git&branches=feature/XXXX-2573&sha1=b3dd6fe0a7db3b78739cf05c79a85bad56b3bc11

      This looks valid according to the Git plugin wiki.

      It used to NOT set the branches and sha1 parameter, e.g. simply ...

      /jenkins/git/notifyCommit?url=ssh%3A%2F%2Fgit%40my-stash-host%3A7999%2Fproject%2Frepository.git

      Since this webhook started calling this endpoint with the sha1 parameter our Jenkins jobs has started setting the GIT_BRANCH variable to detached and not the appropriate branch name.

      Without this sha1 parameter the job output starts with "Started by an SCM change". With this sha1 parameter the job output starts with e.g. "commit notification b3dd6fe0a7db3b78739cf05c79a85bad56b3bc11".

      e.g. Without SHA1 set we see

      Started by an SCM change
      Building on master in workspace /home/jenkins/jobs/My Job/workspace
      > /usr/local/bin/git rev-parse --is-inside-work-tree # timeout=10
      Fetching changes from the remote Git repository
      > /usr/local/bin/git config remote.origin.url ssh://git@my-stash-host:7999/project/repository.git # timeout=10
      Fetching upstream changes from ssh://git@my-stash-host:7999/project/repository.git
      > /usr/local/bin/git --version # timeout=10
      > /usr/local/bin/git fetch --tags --progress ssh://git@my-stash-host:7999/project/repository.git +refs/heads/*:refs/remotes/origin/*
      Seen branch in repository origin/HEAD
      Seen branch in repository origin/feature/XXXX-1018
      Seen branch in repository origin/feature/XXXX-1093
      ...
      
      Seen 293 remote branches
      Checking out Revision b3dd6fe0a7db3b78739cf05c79a85bad56b3bc11 (origin/feature/XXXX-2571)
      

      e.g. With SHA1 set

      commit notification b3dd6fe0a7db3b78739cf05c79a85bad56b3bc11
      Building on master in workspace /home/jenkins/jobs/My Job/workspace
      > /usr/local/bin/git rev-parse --is-inside-work-tree # timeout=10
      Fetching changes from the remote Git repository
      > /usr/local/bin/git config remote.origin.url ssh://git@my-stash-host:7999/project/repository.git # timeout=10
      Fetching upstream changes from ssh://git@my-stash-host:7999/project/repository.git
      > /usr/local/bin/git --version # timeout=10
      > /usr/local/bin/git fetch --tags --progress ssh://git@my-stash-host:7999/project/repository.git +refs/heads/*:refs/remotes/origin/*
      > /usr/local/bin/git rev-parse b3dd6fe0a7db3b78739cf05c79a85bad56b3bc11^{commit} # timeout=10
      Checking out Revision b3dd6fe0a7db3b78739cf05c79a85bad56b3bc11(detached)
      

      Note that Checking out Revision line knows the branch (AND sets GIT_BRANCH variable to the correct branch name) without SHA1 set but it does not know the branch, i.e. it sets detached for the branch name (AND sets GIT_BRANCH to detached).

      Note we have implemented a work around in apache by removing the sha1 parameter from the URL which fixes this for our environment (however we don't benefit from the notifyCommit being explicit about the commit revision to build).

      FYI - our Apache configuration workaround is:

      RewriteEngine On
      
      # Remove branches and sha1 from notify notifyCommit calls
      RewriteCond %{QUERY_STRING} ^url=([^&]*)&branches=([^&]*)&sha1=([^&]*)$ [NC]
      RewriteRule ^ %{REQUEST_URI}?url=%1&branches=%2 [PT]
      

      Attachments

        Issue Links

          Activity

            markewaite Mark Waite added a comment -

            Proposed fix has been merged for inclusion in the first versions after git plugin 2.3 and git plugin 2.2.8.

            markewaite Mark Waite added a comment - Proposed fix has been merged for inclusion in the first versions after git plugin 2.3 and git plugin 2.2.8.

            Code changed in jenkins
            User: Pavel Baranchikov
            Path:
            src/test/java/hudson/plugins/git/GitSCMTest.java
            http://jenkins-ci.org/commit/git-plugin/d7e78e24f0228cee9d588cb010bd6485fdfbcc38
            Log:
            Fixed JUnit tests for JENKINS-24133 on Windows

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Pavel Baranchikov Path: src/test/java/hudson/plugins/git/GitSCMTest.java http://jenkins-ci.org/commit/git-plugin/d7e78e24f0228cee9d588cb010bd6485fdfbcc38 Log: Fixed JUnit tests for JENKINS-24133 on Windows

            Code changed in jenkins
            User: Mark Waite
            Path:
            src/test/java/hudson/plugins/git/GitSCMTest.java
            http://jenkins-ci.org/commit/git-plugin/a1d3f789cf2ad6e430d596081c03d5ff4a34be50
            Log:
            Merge pull request #274 from pbaranchikov/detachedSha1

            Fixed JUnit tests for JENKINS-24133 on Windows

            Compare: https://github.com/jenkinsci/git-plugin/compare/6ab7413b439e...a1d3f789cf2a

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Mark Waite Path: src/test/java/hudson/plugins/git/GitSCMTest.java http://jenkins-ci.org/commit/git-plugin/a1d3f789cf2ad6e430d596081c03d5ff4a34be50 Log: Merge pull request #274 from pbaranchikov/detachedSha1 Fixed JUnit tests for JENKINS-24133 on Windows Compare: https://github.com/jenkinsci/git-plugin/compare/6ab7413b439e...a1d3f789cf2a

            Code changed in jenkins
            User: Pavel Baranchikov
            Path:
            src/test/java/hudson/plugins/git/GitSCMTest.java
            http://jenkins-ci.org/commit/git-plugin/fe438512a07059ecd954e1271d74c6ba24b536e0
            Log:
            Fixed JUnit tests for JENKINS-24133 on Windows

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Pavel Baranchikov Path: src/test/java/hudson/plugins/git/GitSCMTest.java http://jenkins-ci.org/commit/git-plugin/fe438512a07059ecd954e1271d74c6ba24b536e0 Log: Fixed JUnit tests for JENKINS-24133 on Windows
            markewaite Mark Waite added a comment -

            Fix included in git plugin 2.3.1, released 29 Nov 2014

            markewaite Mark Waite added a comment - Fix included in git plugin 2.3.1, released 29 Nov 2014

            People

              ndeloof Nicolas De Loof
              ihomer Ian Homer
              Votes:
              16 Vote for this issue
              Watchers:
              22 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: