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

GIT_BRANCH set to detached when sha1 parameter set in notifyCommit URL

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • git-plugin
    • None

      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]
      

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

              Created:
              Updated:
              Resolved: