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

Jenkins doesn't pass additional parameters to initial build after notifyCommit is requested

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Not A Defect
    • Component/s: git-plugin
    • Labels:
      None
    • Environment:
      Jenkins: v2.105
      GIT plugin: v4.0.0-beta2
      GIT client plugin: v3.0.0-beta3
    • Similar Issues:

      Description

      I am using Multibranch pipeline project driven by declarative Jenkinsfile.
      After new branch is pushed to the origin and new PR is created, Pull Request Notifier for Bitbucket plugin sends notifyCommit request like:

      https://***/git/notifyCommit?url=https://***/bitbucket/scm/jen/jenkins.git&sha1=28c31ee2da09e0e2852c126bc00ddab792ed08df&pullRequestId=25&branches=feature%2FISSUE-12&toBranch=develop&toHash=199317771629da73d0dd557c594fe46c10763958&mergeCommit=&fromHash=28c31ee2da09e0e2852c126bc00ddab792ed08df&action=OPENED&author=***&reviewers="
      

      Jenkins registers this call, creates new job based on the branch name, performs "First time build" but doesn't pass additional parammeters down to the build. Jenkins build output:

      Branch event
       > /opt/rh/rh-git29/root/usr/bin/git-launch.sh rev-parse --is-inside-work-tree # timeout=10
      Setting origin to https://***/bitbucket/scm/jen/jenkins.git
       > /opt/rh/rh-git29/root/usr/bin/git-launch.sh config remote.origin.url https://***/bitbucket/scm/jen/jenkins.git # timeout=10
      Fetching origin...
      Fetching upstream changes from origin
       > /opt/rh/rh-git29/root/usr/bin/git-launch.sh --version # timeout=10
      using GIT_ASKPASS to set credentials AD\jenkins
       > /opt/rh/rh-git29/root/usr/bin/git-launch.sh fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/*
      Seen branch in repository origin/develop
      Seen branch in repository origin/feature/ISSUE-12
      Seen branch in repository origin/master
      Seen 3 remote branches
      Obtained Jenkinsfile from 28c31ee2da09e0e2852c126bc00ddab792ed08df
      Running in Durability level: MAX_SURVIVABILITY
      [Pipeline] node
      Running on Jenkins in /srv/jenkins/workspace/ins-global_feature_ISSUE-12-DYLF54U2KDTIS7XTVZEE5ZFZWJG6M4VJGQQBHGGGSLYIAPZ5OYGQ
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (Declarative: Checkout SCM)
      [Pipeline] checkout
      Cloning the remote Git repository
      Cloning with configured refspecs honoured and without tags
      Cloning repository https://***/bitbucket/scm/jen/jenkins.git
       > /opt/rh/rh-git29/root/usr/bin/git-launch.sh init /srv/jenkins/workspace/ins-global_feature_ISSUE-12-DYLF54U2KDTIS7XTVZEE5ZFZWJG6M4VJGQQBHGGGSLYIAPZ5OYGQ # timeout=10
      Fetching upstream changes from https://***/bitbucket/scm/jen/jenkins.git
       > /opt/rh/rh-git29/root/usr/bin/git-launch.sh --version # timeout=10
      using GIT_ASKPASS to set credentials AD\jenkins
       > /opt/rh/rh-git29/root/usr/bin/git-launch.sh fetch --no-tags --progress https://***/bitbucket/scm/jen/jenkins.git +refs/heads/*:refs/remotes/origin/*
       > /opt/rh/rh-git29/root/usr/bin/git-launch.sh config remote.origin.url https://***/bitbucket/scm/jen/jenkins.git # timeout=10
       > /opt/rh/rh-git29/root/usr/bin/git-launch.sh config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
       > /opt/rh/rh-git29/root/usr/bin/git-launch.sh config remote.origin.url https://***/bitbucket/scm/jen/jenkins.git # timeout=10
      Fetching without tags
      Fetching upstream changes from https://***/bitbucket/scm/jen/jenkins.git
      using GIT_ASKPASS to set credentials AD\jenkins
       > /opt/rh/rh-git29/root/usr/bin/git-launch.sh fetch --no-tags --progress https://***/bitbucket/scm/jen/jenkins.git +refs/heads/*:refs/remotes/origin/*
      Checking out Revision 28c31ee2da09e0e2852c126bc00ddab792ed08df (feature/ISSUE-12)
       > /opt/rh/rh-git29/root/usr/bin/git-launch.sh config core.sparsecheckout # timeout=10
       > /opt/rh/rh-git29/root/usr/bin/git-launch.sh checkout -f 28c31ee2da09e0e2852c126bc00ddab792ed08df
      Commit message: "ISSUE-12 created new feature."
      First time build. Skipping changelog.
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] withEnv
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (Print parameters)
      [Pipeline] echo
      Jenkins parameters:
      [Pipeline] echo
      build number='1'
      [Pipeline] echo
      Parameters passed from Bitbucket:
      [Pipeline] echo
      pullRequestId=''
      [Pipeline] echo
      toBranch=''
      [Pipeline] echo
      toHash=''
      [Pipeline] echo
      mergeCommit=''
      [Pipeline] echo
      fromHash=''
      [Pipeline] echo
      action=''
      [Pipeline] echo
      author=''
      [Pipeline] echo
      reviewers=''
      [Pipeline] }
      

      So at this point I am not able to notify BitBucket about checkstyle violations, send emails, etc. because parameters like pullRequestId or author are empty.

      Next requests to notifyCommit endpoint end up with JENKINS-51875 issue.

      Thank you.

        Attachments

          Activity

          Hide
          markewaite Mark Waite added a comment -

          That behavior is intentional. Additional parameters passed with notifyCommit are ignored.

          I believe authenticated webhooks are allowed to pass additional information and might be useful for this use case.

          Show
          markewaite Mark Waite added a comment - That behavior is intentional. Additional parameters passed with notifyCommit are ignored. I believe authenticated webhooks are allowed to pass additional information and might be useful for this use case.
          Hide
          ferda_mravenec Ferda Mravenec added a comment -

          Hello Mark.
          Thank you for your reply.

          I did not mention that I start Jenkins with:

          -Dhudson.plugins.git.GitStatus.safeParameters=pullRequestId,toBranch,toHash,mergeCommit,fromHash,action,author,reviewers
          

          And according to the documentation:

          http://javadoc.jenkins.io/git/hudson/plugins/git/GitStatus.html#SAFE_PARAMETERS
          

          it should work as expected. Am I missing something?

          Show
          ferda_mravenec Ferda Mravenec added a comment - Hello Mark. Thank you for your reply. I did not mention that I start Jenkins with: -Dhudson.plugins.git.GitStatus.safeParameters=pullRequestId,toBranch,toHash,mergeCommit,fromHash,action,author,reviewers And according to the documentation: http://javadoc.jenkins.io/git/hudson/plugins/git/GitStatus.html#SAFE_PARAMETERS it should work as expected. Am I missing something?
          Hide
          markewaite Mark Waite added a comment -

          Ferda Mravenec that certainly makes a difference. I suspect you'll find that with that command line argument, Freestyle jobs will accept those parameters when passed and Pipeline jobs will not accept them.

          The safeParameters technique is provided in the plugin as a compatibility technique for users of older job types (Freestyle and Matrix). It has not been tested with Pipeline jobs or with Multi-branch Pipeline jobs. I recommend seeking a better way to pass those parameters (authenticated webhook, ...)

          Show
          markewaite Mark Waite added a comment - Ferda Mravenec that certainly makes a difference. I suspect you'll find that with that command line argument, Freestyle jobs will accept those parameters when passed and Pipeline jobs will not accept them. The safeParameters technique is provided in the plugin as a compatibility technique for users of older job types (Freestyle and Matrix). It has not been tested with Pipeline jobs or with Multi-branch Pipeline jobs. I recommend seeking a better way to pass those parameters (authenticated webhook, ...)
          Hide
          ferda_mravenec Ferda Mravenec added a comment -

          Ouch. It will worth to mention that in the documentation. So I bet the JENKINS-51875 is also related to this incompatibility.

          Show
          ferda_mravenec Ferda Mravenec added a comment - Ouch. It will worth to mention that in the documentation. So I bet the JENKINS-51875  is also related to this incompatibility.
          Hide
          markewaite Mark Waite added a comment -

          JENKINS-30178 suggests that the results may be better if the sha1 parameter is removed from the arguments. However, JENKINS-34363 suggests that it did not work for at least one user.

          Show
          markewaite Mark Waite added a comment - JENKINS-30178 suggests that the results may be better if the sha1 parameter is removed from the arguments. However, JENKINS-34363 suggests that it did not work for at least one user.

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ferda_mravenec Ferda Mravenec
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: