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

Plugin not providing values for GIT_COMMITTER_NAME and GIT_AUTHOR_NAME

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Component/s: git-plugin
    • Labels:
      None
    • Similar Issues:

      Description

      I tried to extract  GIT_COMMIT and GIT_COMMITTER_NAME values in my declarative pipeline, I can get value for GIT_COMMIT but values for GIT_COMMITER_NAME is missing.

      Following are steps to extract 

      echo "Git Commit $GIT_COMMIT"
      echo "Env Git Name ${env.GIT_COMMITTER_NAME}"
      echo "Env Git Author Name ${env.GIT_AUTHOR_NAME}"
      echo "Git Author Name $GIT_AUTHOR_NAME"
      echo "Git Commiter Name $GIT_COMMITTER_NAME"
      

      For ${env.GIT_COMMITTER_NAME} its giving null

      For $GIT_COMMITTER_NAME or $GIT_AUTHOR_NAME its throwing following error

      groovy.lang.MissingPropertyException: No such property: GIT_AUTHOR_NAME for class: groovy.lang.Binding
      at groovy.lang.Binding.getVariable(Binding.java:63)
      at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:242)
      at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288)
      at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292)
      at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:268)
      at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:268)
      at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
      at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
      at WorkflowScript.run(WorkflowScript:45)
      

      Global variable is also set

      I verified on my machine

      $ git config --global user.name
      imran raza khan

       

        Attachments

          Activity

          Hide
          markewaite Mark Waite added a comment - - edited

          I believe you're making syntactic mistakes rather than missing the values of GIT_COMMITTER_NAME and GIT_AUTHOR_NAME. Refer to the example declarative pipeline job in my JENKINS-52511 branch for working examples.

          The GIT_COMMITTER_NAME and GIT_AUTHOR_NAME in that example show that JENKINS-45489 is still an open bug. That bug reports that the value assigned to GIT_COMMITTER_NAME and GIT_AUTHOR_NAME is incorrect if a Pipeline shared library was loaded along with the working repository. The value assigned to GIT_COMMIT is the SHA-1 of the commit which declarative pipeline used in its implicit checkout. Unfortunately, the value assigned to GIT_AUTHOR_NAME and GIT_COMMITTER_NAME is from the most recent commit to the Pipeline shared library.

          You might also refer to the related Jenkins minute video.

          Show
          markewaite Mark Waite added a comment - - edited I believe you're making syntactic mistakes rather than missing the values of GIT_COMMITTER_NAME and GIT_AUTHOR_NAME . Refer to the example declarative pipeline job in my JENKINS-52511 branch for working examples. The GIT_COMMITTER_NAME and GIT_AUTHOR_NAME in that example show that JENKINS-45489 is still an open bug. That bug reports that the value assigned to GIT_COMMITTER_NAME and GIT_AUTHOR_NAME is incorrect if a Pipeline shared library was loaded along with the working repository. The value assigned to GIT_COMMIT is the SHA-1 of the commit which declarative pipeline used in its implicit checkout. Unfortunately, the value assigned to GIT_AUTHOR_NAME and GIT_COMMITTER_NAME is from the most recent commit to the Pipeline shared library. You might also refer to the related Jenkins minute video .
          Hide
          imranrazakhan imran khan added a comment - - edited

          I used your provided code in windows and following is output

          just changed like below

          ws(dir: WORKSPACE )

          OUTPUT:

          Started by user Imran Raza Khan
          > git.exe rev-parse --is-inside-work-tree # timeout=10
          Setting origin to https://my.com/scm/java/my.git
          > git.exe config remote.origin.url https://my.com/scm/java/my.git # timeout=10
          Fetching origin...
          Fetching upstream changes from origin
          > git.exe --version # timeout=10
          using GIT_ASKPASS to set credentials
          > git.exe fetch --tags --progress origin +refs/heads/:refs/remotes/origin/
          Seen branch in repository origin/TEST-555
          Seen branch in repository origin/TESTJENKINS
          Seen branch in repository origin/master
          Seen branch in repository origin/test
          Seen 4 remote branches
          Obtained Jenkinsfile from 6895d05d313977e329519d17c5074a0b334be8cf
          Running in Durability level: MAX_SURVIVABILITY
          [Pipeline] node
          Running on Jenkins in C:\Users\imran\.jenkins\workspace\e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A
          [Pipeline] {
          [Pipeline] stage
          [Pipeline]

          { (Declarative: Checkout SCM) [Pipeline] checkout > git.exe rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > git.exe config remote.origin.url https://my.com/scm/java/my.git # timeout=10 Fetching without tags Fetching upstream changes from https://my.com/scm/java/my.git > git.exe --version # timeout=10 using GIT_ASKPASS to set credentials > git.exe fetch --no-tags --progress https://my.com/scm/java/my.git +refs/heads/*:refs/remotes/origin/* Checking out Revision 6895d05d313977e329519d17c5074a0b334be8cf (TESTJENKINS) > git.exe config core.sparsecheckout # timeout=10 > git.exe checkout -f 6895d05d313977e329519d17c5074a0b334be8cf Commit message: "update Jenkins Pipeline WIP" > git.exe rev-list --no-walk 211e9cf1009aa872739b9c5d21289711c332d0af # timeout=10 [Pipeline] }

          [Pipeline] // stage
          [Pipeline] withEnv
          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (parallel)
          [Pipeline] parallel
          [Pipeline] [windows] { (Branch: windows)
          [Pipeline] [windows] stage
          [Pipeline] [windows] { (windows)
          [Pipeline] [windows] echo
          [windows] pipeline GIT_COMMIT before windows ws is 6895d05d313977e329519d17c5074a0b334be8cf
          [Pipeline] [windows] ws
          [windows] Running in C:\Users\imran\.jenkins\workspace\e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A@2
          [Pipeline] [windows]

          { [Pipeline] [windows] echo [windows] pipeline GIT_AUTHOR_NAME in windows ws is null [Pipeline] [windows] bat [windows] [e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A@2] Running batch script [windows] [windows] C:\Users\imran\.jenkins\workspace\e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A@2>echo bat GIT_COMMITTER_NAME in windows ws is [windows] bat GIT_COMMITTER_NAME in windows ws is [Pipeline] [windows] }

          [Pipeline] [windows] // ws
          [Pipeline] [windows] echo
          [windows] pipeline GIT_COMMIT after windows ws is 6895d05d313977e329519d17c5074a0b334be8cf
          [Pipeline] [windows] bat
          [windows] [e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A] Running batch script
          [windows]
          [windows] C:\Users\imran\.jenkins\workspace\e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A>echo bat GIT_COMMIT after windows ws is 6895d05d313977e329519d17c5074a0b334be8cf
          [windows] bat GIT_COMMIT after windows ws is 6895d05d313977e329519d17c5074a0b334be8cf
          [Pipeline] [windows] bat
          [windows] [e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A] Running batch script
          [windows]
          [windows] C:\Users\imran\.jenkins\workspace\e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A>echo hello windows from IMRAN-118
          [windows] hello windows from IMRAN-118
          [Pipeline] [windows] }
          [Pipeline] [windows] // stage
          [Pipeline] [windows] }
          [Pipeline] // parallel
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // withEnv
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS

          Show
          imranrazakhan imran khan added a comment - - edited I used your provided code in windows and following is output just changed like below ws(dir: WORKSPACE ) OUTPUT: Started by user Imran Raza Khan > git.exe rev-parse --is-inside-work-tree # timeout=10 Setting origin to https://my.com/scm/java/my.git > git.exe config remote.origin.url https://my.com/scm/java/my.git # timeout=10 Fetching origin... Fetching upstream changes from origin > git.exe --version # timeout=10 using GIT_ASKPASS to set credentials > git.exe fetch --tags --progress origin +refs/heads/ :refs/remotes/origin/ Seen branch in repository origin/TEST-555 Seen branch in repository origin/TESTJENKINS Seen branch in repository origin/master Seen branch in repository origin/test Seen 4 remote branches Obtained Jenkinsfile from 6895d05d313977e329519d17c5074a0b334be8cf Running in Durability level: MAX_SURVIVABILITY [Pipeline] node Running on Jenkins in C:\Users\imran\.jenkins\workspace\e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A [Pipeline] { [Pipeline] stage [Pipeline] { (Declarative: Checkout SCM) [Pipeline] checkout > git.exe rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > git.exe config remote.origin.url https://my.com/scm/java/my.git # timeout=10 Fetching without tags Fetching upstream changes from https://my.com/scm/java/my.git > git.exe --version # timeout=10 using GIT_ASKPASS to set credentials > git.exe fetch --no-tags --progress https://my.com/scm/java/my.git +refs/heads/*:refs/remotes/origin/* Checking out Revision 6895d05d313977e329519d17c5074a0b334be8cf (TESTJENKINS) > git.exe config core.sparsecheckout # timeout=10 > git.exe checkout -f 6895d05d313977e329519d17c5074a0b334be8cf Commit message: "update Jenkins Pipeline WIP" > git.exe rev-list --no-walk 211e9cf1009aa872739b9c5d21289711c332d0af # timeout=10 [Pipeline] } [Pipeline] // stage [Pipeline] withEnv [Pipeline] { [Pipeline] stage [Pipeline] { (parallel) [Pipeline] parallel [Pipeline] [windows] { (Branch: windows) [Pipeline] [windows] stage [Pipeline] [windows] { (windows) [Pipeline] [windows] echo [windows] pipeline GIT_COMMIT before windows ws is 6895d05d313977e329519d17c5074a0b334be8cf [Pipeline] [windows] ws [windows] Running in C:\Users\imran\.jenkins\workspace\e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A@2 [Pipeline] [windows] { [Pipeline] [windows] echo [windows] pipeline GIT_AUTHOR_NAME in windows ws is null [Pipeline] [windows] bat [windows] [e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A@2] Running batch script [windows] [windows] C:\Users\imran\.jenkins\workspace\e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A@2>echo bat GIT_COMMITTER_NAME in windows ws is [windows] bat GIT_COMMITTER_NAME in windows ws is [Pipeline] [windows] } [Pipeline] [windows] // ws [Pipeline] [windows] echo [windows] pipeline GIT_COMMIT after windows ws is 6895d05d313977e329519d17c5074a0b334be8cf [Pipeline] [windows] bat [windows] [e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A] Running batch script [windows] [windows] C:\Users\imran\.jenkins\workspace\e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A>echo bat GIT_COMMIT after windows ws is 6895d05d313977e329519d17c5074a0b334be8cf [windows] bat GIT_COMMIT after windows ws is 6895d05d313977e329519d17c5074a0b334be8cf [Pipeline] [windows] bat [windows] [e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A] Running batch script [windows] [windows] C:\Users\imran\.jenkins\workspace\e-multipipeline_TESTJENKINS-WB7B2SPPZGFQC74ER3V7H4MZCMM7MPKNLHALQPJ5OVCWHK3MYM7A>echo hello windows from IMRAN-118 [windows] hello windows from IMRAN-118 [Pipeline] [windows] } [Pipeline] [windows] // stage [Pipeline] [windows] } [Pipeline] // parallel [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS
          Hide
          markewaite Mark Waite added a comment -

          That output is not at all unreasonable based on JENKINS-45489.

          If your goal is to determine the author name or committer name of the commit which is the HEAD of the current repository, then you'll need to use a technique like I've illustrated in the JENKINS-52511/Jenkinsfile.

          There are earlier bug reports which reminded me that the meaning of GIT_COMMITTER_NAME in a Freestyle job may not be what people are expecting. A 2013 comment in JENKINS-20386 hints that the GIT_COMMITTER_NAME in Freestyle jobs means "the name that will be used for any commits from this repository". In that context at that time, it did not mean "the name of the committer of the most recent commit in the working directory".

          Show
          markewaite Mark Waite added a comment - That output is not at all unreasonable based on JENKINS-45489 . If your goal is to determine the author name or committer name of the commit which is the HEAD of the current repository, then you'll need to use a technique like I've illustrated in the JENKINS-52511/Jenkinsfile . There are earlier bug reports which reminded me that the meaning of GIT_COMMITTER_NAME in a Freestyle job may not be what people are expecting. A 2013 comment in JENKINS-20386 hints that the GIT_COMMITTER_NAME in Freestyle jobs means "the name that will be used for any commits from this repository". In that context at that time, it did not mean "the name of the committer of the most recent commit in the working directory".

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            imranrazakhan imran khan
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: