The return value of the git step should be the commit hash, etc., and there should be a way to pass that back in to a subsequent git step in case you want to check out the same revision in another workspace (without copying files).

      The workaround is to archive and then unarchive sources.

          [JENKINS-26100] SCM steps should return revision state

          Code changed in jenkins
          User: Andrew Bayer
          Path:
          pom.xml
          src/main/java/org/jenkinsci/plugins/workflow/steps/scm/SCMStep.java
          src/main/java/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStep.java
          src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStep/config.jelly
          src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStep/help.html
          src/test/java/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStepTest.java
          http://jenkins-ci.org/commit/workflow-scm-step-plugin/bec924c64a8f19efbd7f6f08af9d879636dcf4e4
          Log:
          JENKINS-26100 Add withCheckout(scm)

          { body }

          step.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: pom.xml src/main/java/org/jenkinsci/plugins/workflow/steps/scm/SCMStep.java src/main/java/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStep.java src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStep/config.jelly src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStep/help.html src/test/java/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStepTest.java http://jenkins-ci.org/commit/workflow-scm-step-plugin/bec924c64a8f19efbd7f6f08af9d879636dcf4e4 Log: JENKINS-26100 Add withCheckout(scm) { body } step.

          Code changed in jenkins
          User: Andrew Bayer
          Path:
          pom.xml
          src/main/java/org/jenkinsci/plugins/workflow/steps/scm/SCMStep.java
          src/main/java/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStep.java
          src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStep/config.jelly
          src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStep/help.html
          src/test/java/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStepTest.java
          http://jenkins-ci.org/commit/workflow-scm-step-plugin/dbcfe52ad81d16fe3dfdc5ce642f49720aff36e3
          Log:
          Revert "JENKINS-26100 Add withCheckout(scm)

          { body }

          step."

          This reverts commit bec924c64a8f19efbd7f6f08af9d879636dcf4e4.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: pom.xml src/main/java/org/jenkinsci/plugins/workflow/steps/scm/SCMStep.java src/main/java/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStep.java src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStep/config.jelly src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStep/help.html src/test/java/org/jenkinsci/plugins/workflow/steps/scm/WithCheckoutStepTest.java http://jenkins-ci.org/commit/workflow-scm-step-plugin/dbcfe52ad81d16fe3dfdc5ce642f49720aff36e3 Log: Revert " JENKINS-26100 Add withCheckout(scm) { body } step." This reverts commit bec924c64a8f19efbd7f6f08af9d879636dcf4e4.

          Code changed in jenkins
          User: Andrew Bayer
          Path:
          pom.xml
          src/test/java/org/jenkinsci/plugins/workflow/steps/scm/SCMStepTest.java
          http://jenkins-ci.org/commit/workflow-scm-step-plugin/65952d9ba01c2d79d41d3c5c32cbc22580df1b03
          Log:
          Switch to using svn for JENKINS-26100 test so we can release.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: pom.xml src/test/java/org/jenkinsci/plugins/workflow/steps/scm/SCMStepTest.java http://jenkins-ci.org/commit/workflow-scm-step-plugin/65952d9ba01c2d79d41d3c5c32cbc22580df1b03 Log: Switch to using svn for JENKINS-26100 test so we can release.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          Jenkinsfile
          pom.xml
          src/main/java/org/jenkinsci/plugins/workflow/steps/scm/SCMStep.java
          src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/GenericSCMStep/help.html
          src/test/java/org/jenkinsci/plugins/workflow/steps/scm/SCMStepTest.java
          http://jenkins-ci.org/commit/workflow-scm-step-plugin/2d2c718cb1c1b75d791c4e858571fdc9fa1b3951
          Log:
          Merge pull request #16 from abayer/jenkins-26100

          JENKINS-26100 Return a map of SCM-contributed variables

          Compare: https://github.com/jenkinsci/workflow-scm-step-plugin/compare/6b6716f56d97...2d2c718cb1c1

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: Jenkinsfile pom.xml src/main/java/org/jenkinsci/plugins/workflow/steps/scm/SCMStep.java src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/GenericSCMStep/help.html src/test/java/org/jenkinsci/plugins/workflow/steps/scm/SCMStepTest.java http://jenkins-ci.org/commit/workflow-scm-step-plugin/2d2c718cb1c1b75d791c4e858571fdc9fa1b3951 Log: Merge pull request #16 from abayer/jenkins-26100 JENKINS-26100 Return a map of SCM-contributed variables Compare: https://github.com/jenkinsci/workflow-scm-step-plugin/compare/6b6716f56d97...2d2c718cb1c1

          Andrew Bayer added a comment -

          Waiting to actually resolve until https://github.com/jenkinsci/git-plugin/pull/492 is merged/released.

          Andrew Bayer added a comment - Waiting to actually resolve until https://github.com/jenkinsci/git-plugin/pull/492 is merged/released.

          Code changed in jenkins
          User: Andrew Bayer
          Path:
          pom.xml
          src/main/java/hudson/plugins/git/GitSCM.java
          http://jenkins-ci.org/commit/git-plugin/47f738c54c6e8f5ead678aacfda1faa1d7433db8
          Log:
          JENKINS-26100 Switch buildEnvVars and others to Run

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: pom.xml src/main/java/hudson/plugins/git/GitSCM.java http://jenkins-ci.org/commit/git-plugin/47f738c54c6e8f5ead678aacfda1faa1d7433db8 Log: JENKINS-26100 Switch buildEnvVars and others to Run

          Code changed in jenkins
          User: Mark Waite
          Path:
          pom.xml
          src/main/java/hudson/plugins/git/GitSCM.java
          http://jenkins-ci.org/commit/git-plugin/907253d7149fdd53de3389528e163be8b5e298ef
          Log:
          Merge pull request #492 from abayer/jenkins-26100

          JENKINS-26100 Switch buildEnvVars and others to Run

          Compare: https://github.com/jenkinsci/git-plugin/compare/79c66ebb8958...907253d7149f

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Mark Waite Path: pom.xml src/main/java/hudson/plugins/git/GitSCM.java http://jenkins-ci.org/commit/git-plugin/907253d7149fdd53de3389528e163be8b5e298ef Log: Merge pull request #492 from abayer/jenkins-26100 JENKINS-26100 Switch buildEnvVars and others to Run Compare: https://github.com/jenkinsci/git-plugin/compare/79c66ebb8958...907253d7149f

          Jesse Glick added a comment -

          I think at this point everything is merged, and only git plugin changes are still awaiting release.

          Jesse Glick added a comment - I think at this point everything is merged, and only git plugin changes are still awaiting release.

          Mark Waite added a comment -

          Git plugin 3.3.1 has been released with the necessary pull request merged.

          Mark Waite added a comment - Git plugin 3.3.1 has been released with the necessary pull request merged.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          src/main/java/hudson/plugins/git/GitSCM.java
          src/main/resources/hudson/plugins/git/GitSCM/buildEnv.groovy
          src/main/resources/hudson/plugins/git/GitSCM/buildEnv.properties
          http://jenkins-ci.org/commit/git-plugin/53984ad06a8d8a38cce1857e977006a0adbd3e13
          Log:
          JENKINS-26100 Supply GitSCM/buildEnv.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/java/hudson/plugins/git/GitSCM.java src/main/resources/hudson/plugins/git/GitSCM/buildEnv.groovy src/main/resources/hudson/plugins/git/GitSCM/buildEnv.properties http://jenkins-ci.org/commit/git-plugin/53984ad06a8d8a38cce1857e977006a0adbd3e13 Log: JENKINS-26100 Supply GitSCM/buildEnv.

          Code changed in jenkins
          User: Mark Waite
          Path:
          src/main/java/hudson/plugins/git/GitSCM.java
          src/main/resources/hudson/plugins/git/GitSCM/buildEnv.groovy
          src/main/resources/hudson/plugins/git/GitSCM/buildEnv.properties
          http://jenkins-ci.org/commit/git-plugin/2cfbf64ed55f9a23ccd576c66fa4deb83dabe91a
          Log:
          Merge pull request #508 from jglick/buildEnv

          JENKINS-26100 Supply GitSCM/buildEnv

          Compare: https://github.com/jenkinsci/git-plugin/compare/87a76efafa62...2cfbf64ed55f

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Mark Waite Path: src/main/java/hudson/plugins/git/GitSCM.java src/main/resources/hudson/plugins/git/GitSCM/buildEnv.groovy src/main/resources/hudson/plugins/git/GitSCM/buildEnv.properties http://jenkins-ci.org/commit/git-plugin/2cfbf64ed55f9a23ccd576c66fa4deb83dabe91a Log: Merge pull request #508 from jglick/buildEnv JENKINS-26100 Supply GitSCM/buildEnv Compare: https://github.com/jenkinsci/git-plugin/compare/87a76efafa62...2cfbf64ed55f

          Code changed in jenkins
          User: Jesse Glick
          Path:
          src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/GenericSCMStep/help.html
          src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/GenericSCMStep/help.jelly
          http://jenkins-ci.org/commit/workflow-scm-step-plugin/0008adc79cb5617971d5447c463d2ca1a0799e10
          Log:
          JENKINS-26100 Display buildEnv views of available SCM installations.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/GenericSCMStep/help.html src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/GenericSCMStep/help.jelly http://jenkins-ci.org/commit/workflow-scm-step-plugin/0008adc79cb5617971d5447c463d2ca1a0799e10 Log: JENKINS-26100 Display buildEnv views of available SCM installations.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/GenericSCMStep/help.html
          src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/GenericSCMStep/help.jelly
          http://jenkins-ci.org/commit/workflow-scm-step-plugin/9ccae57a8d5b746e10dfcdc3f44400729d7da27f
          Log:
          Merge pull request #18 from jglick/doc-JENKINS-26100

          JENKINS-26100 Display buildEnv views of available SCM installations

          Compare: https://github.com/jenkinsci/workflow-scm-step-plugin/compare/17a9946bfe3f...9ccae57a8d5b

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/GenericSCMStep/help.html src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/GenericSCMStep/help.jelly http://jenkins-ci.org/commit/workflow-scm-step-plugin/9ccae57a8d5b746e10dfcdc3f44400729d7da27f Log: Merge pull request #18 from jglick/doc- JENKINS-26100 JENKINS-26100 Display buildEnv views of available SCM installations Compare: https://github.com/jenkinsci/workflow-scm-step-plugin/compare/17a9946bfe3f...9ccae57a8d5b

          Code changed in jenkins
          User: Jesse Glick
          Path:
          src/main/resources/org/jenkinsci/plugins/workflow/cps/EnvActionImpl/Binder/help.jelly
          http://jenkins-ci.org/commit/workflow-cps-plugin/1a69342650bd1846d479c296436bb8969559ca16
          Log:
          JENKINS-26100 Updating documentation.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/resources/org/jenkinsci/plugins/workflow/cps/EnvActionImpl/Binder/help.jelly http://jenkins-ci.org/commit/workflow-cps-plugin/1a69342650bd1846d479c296436bb8969559ca16 Log: JENKINS-26100 Updating documentation.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          src/main/resources/org/jenkinsci/plugins/workflow/cps/EnvActionImpl/Binder/help.jelly
          http://jenkins-ci.org/commit/workflow-cps-plugin/2e9b83495d9aa91dca4479f03c35daaeb275b22f
          Log:
          Merge pull request #153 from jglick/doc-JENKINS-26100

          JENKINS-26100 Updating documentation

          Compare: https://github.com/jenkinsci/workflow-cps-plugin/compare/b78991523e2f...2e9b83495d9a

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/resources/org/jenkinsci/plugins/workflow/cps/EnvActionImpl/Binder/help.jelly http://jenkins-ci.org/commit/workflow-cps-plugin/2e9b83495d9aa91dca4479f03c35daaeb275b22f Log: Merge pull request #153 from jglick/doc- JENKINS-26100 JENKINS-26100 Updating documentation Compare: https://github.com/jenkinsci/workflow-cps-plugin/compare/b78991523e2f...2e9b83495d9a

          Code changed in jenkins
          User: Jesse Glick
          Path:
          src/main/resources/hudson/plugins/mercurial/MercurialSCM/buildEnv.groovy
          src/main/resources/hudson/plugins/mercurial/MercurialSCM/buildEnv.properties
          http://jenkins-ci.org/commit/mercurial-plugin/16fb1feb2499c01f4f44117d96691f508c00f10f
          Log:
          JENKINS-26100 Supply MercurialSCM/buildEnv.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/resources/hudson/plugins/mercurial/MercurialSCM/buildEnv.groovy src/main/resources/hudson/plugins/mercurial/MercurialSCM/buildEnv.properties http://jenkins-ci.org/commit/mercurial-plugin/16fb1feb2499c01f4f44117d96691f508c00f10f Log: JENKINS-26100 Supply MercurialSCM/buildEnv.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          src/main/resources/hudson/plugins/mercurial/MercurialSCM/buildEnv.groovy
          src/main/resources/hudson/plugins/mercurial/MercurialSCM/buildEnv.properties
          http://jenkins-ci.org/commit/mercurial-plugin/8e0581ac7045aedfd2f34ea6fa01d90618df6b3c
          Log:
          Merge pull request #104 from jglick/buildEnv

          JENKINS-26100 Supply MercurialSCM/buildEnv

          Compare: https://github.com/jenkinsci/mercurial-plugin/compare/bfc7cbd995af...8e0581ac7045

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/resources/hudson/plugins/mercurial/MercurialSCM/buildEnv.groovy src/main/resources/hudson/plugins/mercurial/MercurialSCM/buildEnv.properties http://jenkins-ci.org/commit/mercurial-plugin/8e0581ac7045aedfd2f34ea6fa01d90618df6b3c Log: Merge pull request #104 from jglick/buildEnv JENKINS-26100 Supply MercurialSCM/buildEnv Compare: https://github.com/jenkinsci/mercurial-plugin/compare/bfc7cbd995af...8e0581ac7045

          So, I am a bit confused here. This ticket has been resolved but I'm not sure what combination of versions (core, plugins, etc.) are needed in order to make this work. Could someone clarify those particulars?

          Kevin Phillips added a comment - So, I am a bit confused here. This ticket has been resolved but I'm not sure what combination of versions (core, plugins, etc.) are needed in order to make this work. Could someone clarify those particulars?

          Mark Waite added a comment -

          Git plugin 3.4.1 includes the necessary change, though JENKINS-45489 shows that some of the entries in the returned map seem to include incorrect data. JENKINS-45489 includes more details of the testing and could also be used as an example of how to read the information.

          I don't know the versions of the other SCM plugins which have that capability.

          Mark Waite added a comment - Git plugin 3.4.1 includes the necessary change, though JENKINS-45489 shows that some of the entries in the returned map seem to include incorrect data. JENKINS-45489 includes more details of the testing and could also be used as an example of how to read the information. I don't know the versions of the other SCM plugins which have that capability.

          Hmmm - I have Git plugin v3.4.1 installed, but the following snippet of code returns 'null'. Am I doing something wrong?

           

          node {
              def retval = checkout (changelog: true, poll: true, scm: [$class: 'GitSCM', ... other params for the git checkout])
              echo retval.toString()   // <--- prints 'null'
          }
          

          Kevin Phillips added a comment - Hmmm - I have Git plugin v3.4.1 installed, but the following snippet of code returns 'null'. Am I doing something wrong?   node {     def retval = checkout (changelog: true , poll: true , scm: [$class: 'GitSCM' , ... other params for the git checkout])     echo retval.toString()   // <--- prints ' null ' }

          Mark Waite added a comment -

          I don't know how groovy .toString() of a map behaves. The retval is a map. You can see an example of the check I'm running in my test pipeline, if that helps

          Mark Waite added a comment - I don't know how groovy .toString() of a map behaves. The retval is a map. You can see an example of the check I'm running in my test pipeline, if that helps

          Yeah, that's why I asked. It looks like my snippet from above should work but it doesn't so something on my system must need to be updated or something. I'd like to know which bits I'm missing to make it work.

          Just to be clear, the return value from checkout() is actually null on my system, so it has nothing to do with the toString() method. Here's a variation to illustrate:

           

          node {
              def retval = checkout (...)
              if (retval == null) echo "Undefined"
          }

          This snippet prints out "Undefined" in the log.

          Kevin Phillips added a comment - Yeah, that's why I asked. It looks like my snippet from above should work but it doesn't so something on my system must need to be updated or something. I'd like to know which bits I'm missing to make it work. Just to be clear, the return value from checkout() is actually null on my system, so it has nothing to do with the toString() method. Here's a variation to illustrate:   node { def retval = checkout (...) if (retval == null ) echo "Undefined" } This snippet prints out "Undefined" in the log.

          Roman Pickl added a comment -

          just wanted to add that

          GIT_REV=checkout(scm).GIT_COMMIT

          works for us when run as part of a declarative pipeline within script{}

          Roman Pickl added a comment - just wanted to add that GIT_REV=checkout(scm).GIT_COMMIT works for us when run as part of a declarative pipeline within script{}

          Mark Waite added a comment -

          leedega, my working sample is using scripted pipeline. Since romanp's working sample is using declarative, I'm confident it works in both cases with the latest plugin versions.

          I run my tests using the plugin versions stored in my lts-with-plugins repository. If you'd like to compare versions, you could clone that repository (you'll need git lfs, since it is LFS enabled).

          Mark Waite added a comment - leedega , my working sample is using scripted pipeline. Since romanp 's working sample is using declarative, I'm confident it works in both cases with the latest plugin versions. I run my tests using the plugin versions stored in my lts-with-plugins repository . If you'd like to compare versions, you could clone that repository (you'll need git lfs, since it is LFS enabled).

          markewaite romanp What version of the jenkins core are you both using? I'm currently on LTS v2.46.3. Maybe there is some feature in a newer core version that is required to make this work as well.

          Kevin Phillips added a comment - markewaite romanp  What version of the jenkins core are you both using? I'm currently on LTS v2.46.3. Maybe there is some feature in a newer core version that is required to make this work as well.

          Mark Waite added a comment -

          I doubt the differences between Jenkins 2.46.3 (the prior LTS) and 2.60.2 (the current LTS and the version I'm using) are enough to matter here. Have you checked your plugins for upgrades?

          Mark Waite added a comment - I doubt the differences between Jenkins 2.46.3 (the prior LTS) and 2.60.2 (the current LTS and the version I'm using) are enough to matter here. Have you checked your plugins for upgrades?

          Yes, I updated the Git plugin and all pipeline* plugins to the latest version yesterday to try and get this working. This is what prompted me to post my original question. I can try upgrading the Jenkins core on one of my sandboxes just to see if that makes any difference just in case.

          Kevin Phillips added a comment - Yes, I updated the Git plugin and all pipeline* plugins to the latest version yesterday to try and get this working. This is what prompted me to post my original question. I can try upgrading the Jenkins core on one of my sandboxes just to see if that makes any difference just in case.

          Jesse Glick added a comment -

          You need Jenkins core 2.60 or later. Messaging has been added to the checkout step’s inline help already.

          Jesse Glick added a comment - You need Jenkins core 2.60 or later. Messaging has been added to the checkout step’s inline help already.

          Roman Pickl added a comment -

          we are running Jenkins ver. 2.60.2

          Roman Pickl added a comment - we are running Jenkins ver. 2.60.2

          With above changes, will it be possible to get the Environment list in the following way,

          <snip>

          Run run;

          EnvVars env = run.getEnvironment(listener);

          env.get("GIT_URL");

          </snip>

           

          Hariharan Kuppusamy added a comment - With above changes, will it be possible to get the Environment list in the following way, <snip> Run run; EnvVars env = run.getEnvironment(listener); env.get("GIT_URL"); </snip>  

          Mark Waite added a comment -

          hariharan The environment variables are returned by the pipeline checkout command as a map

          def map_of_checkout_vars = checkout([$class: 'GitSCM'])
          

          Refer to my Jenkinsfile for an example using those variables.

          Mark Waite added a comment - hariharan The environment variables are returned by the pipeline checkout command as a map def map_of_checkout_vars = checkout([$class: 'GitSCM']) Refer to my Jenkinsfile for an example using those variables.

          Simon La Personne added a comment - - edited

          Hello,

          I have the same issue than leedega, with Jenkins 2.60.2 and Git plugin 3.5.0 : checkout command does not return anything.

          Is an other plugin needed to recover and process these variables ?

          Simon La Personne added a comment - - edited Hello, I have the same issue than leedega , with Jenkins 2.60.2 and Git plugin 3.5.0 : checkout command does not return anything. Is an other plugin needed to recover and process these variables ?

          Mark Waite added a comment -

          slapersonne I'm using Jenkins 2.60.2 with the plugins listed in my lts-with-plugin repository. You could compare your plugin list to those plugins to detect differences.

          Mark Waite added a comment - slapersonne I'm using Jenkins 2.60.2 with the plugins listed in my lts-with-plugin repository . You could compare your plugin list to those plugins to detect differences.

          Jesse Glick added a comment - - edited

          You need to update workflow-scm-step.

          Jesse Glick added a comment - - edited You need to update workflow-scm-step .

          Thank you for your answers, with workflow-scm-step updated to 2.6 the variables can well be recovered within the map.

          Simon La Personne added a comment - Thank you for your answers, with workflow-scm-step updated to 2.6 the variables can well be recovered within the map.

          jglick

          Hello, I had this support ticket https://support.cloudbees.com/hc/en-us/requests/47538 marked as resolved based on the work done to resolve this issue. My request was for pipeline to support GHPRB style "skip build phrase". Forgive me but it's not obvious how I would leverage the fix for this issue to give me the "skip build phrase" type functionality. Could you give some pointers on that?

          Thanks

          Justin Rainwater added a comment - jglick Hello, I had this support ticket  https://support.cloudbees.com/hc/en-us/requests/47538  marked as resolved based on the work done to resolve this issue. My request was for pipeline to support GHPRB style "skip build phrase". Forgive me but it's not obvious how I would leverage the fix for this issue to give me the "skip build phrase" type functionality. Could you give some pointers on that? Thanks

          Mark Waite added a comment -

          rainwaj I assume they were thinking that one or more of the values in the map returned from the pipeline checkout() step could be used inside your pipeline script. The names include the GIT_COMMIT, GIT_AUTHOR, and GIT_AUTHOR, and the associated values come from the most recent commit on that branch.

          I think they intended that you would use those values to decide if the pipeline should finish early, rather than continuing through to the end of the pipeline.

          Mark Waite added a comment - rainwaj I assume they were thinking that one or more of the values in the map returned from the pipeline checkout() step could be used inside your pipeline script. The names include the GIT_COMMIT, GIT_AUTHOR, and GIT_AUTHOR, and the associated values come from the most recent commit on that branch. I think they intended that you would use those values to decide if the pipeline should finish early, rather than continuing through to the end of the pipeline.

          Thanks for the reply markewaite. Do you happen to know if checkout() is also returning the PR title/description and/or comments? I think that's the only way this new functionality could provide the same value as "Skip Build Phrase" from GHPRB.

          Justin Rainwater added a comment - Thanks for the reply markewaite . Do you happen to know if checkout() is also returning the PR title/description and/or comments? I think that's the only way this new functionality could provide the same value as "Skip Build Phrase" from GHPRB.

          Mark Waite added a comment -

          rainwaj I know that it is not returning any pull request specific information (at least not at this time). It returns information about the commit and its branch, not about the pull request.

          Mark Waite added a comment - rainwaj I know that it is not returning any pull request specific information (at least not at this time). It returns information about the commit and its branch, not about the pull request.

          Gauthier R. added a comment -

          Hello, i asked a question on StackOverflow, i am using JGit and cannot get any information from scm checkout using the latest version of the plugin.

          Would you know if this is a limitation of JGit itself, or from the SCM steps plugin ?

          Gauthier R. added a comment - Hello, i asked a question on StackOverflow , i am using JGit and cannot get any information from scm checkout using the latest version of the plugin. Would you know if this is a limitation of JGit itself, or from the SCM steps plugin ?

          Mark Waite added a comment -

          gotson in your stackoverflow question, you mention that you're running git plugin 3.3.0. The fix was not included in the git plugin until 3.3.2. You'll need to update to at least git plugin 3.3.2.

          Mark Waite added a comment - gotson in your stackoverflow question, you mention that you're running git plugin 3.3.0. The fix was not included in the git plugin until 3.3.2. You'll need to update to at least git plugin 3.3.2.

          Gauthier R. added a comment -

          markewaite thanks a lot for your help, upgrading the Git Plugin to 3.3.2 indeed solved my problem !

          Gauthier R. added a comment - markewaite thanks a lot for your help, upgrading the Git Plugin to 3.3.2 indeed solved my problem !

          Norbert Lange added a comment -

          I might be dense, but I still dont understand how I would do this with a declarative pipeline (without script blocks).
          Any help here?

          withCheckout is nowhere to be found

          the env variables are not set by default:

          pipeline {
              agent none
              stages {
                  stage('checkout') {
                      post { always { deleteDir() } }
                      agent any
                      steps {
                          checkout([$class: 'GitSCM', 
                              userRemoteConfigs: [[url: 'https://github.com/docker/for-linux.git']]])
                          sh 'set'
                      }
                  }
              }
          }
          

          trying to stuff into a withEnv block fails with `java.lang.UnsupportedOperationException: must specify $class with an implementation of interface java.util.List`

          pipeline {
              agent none
              stages {
                  stage('checkout') {
                      post { always { deleteDir() } }
                      agent any
                      steps {
                          withEnv(checkout([$class: 'GitSCM', 
                              userRemoteConfigs: [[url: 'https://github.com/docker/for-linux.git']]])) {
                                  sh 'set'  
                              }
                      }
                  }
              }
          }
          

          Jenkins ver. 2.219 (docker alpine installation)
          git 4.1.1 true
          git-client 3.1.1 true
          workflow-scm-step 2.10 true

          Norbert Lange added a comment - I might be dense, but I still dont understand how I would do this with a declarative pipeline (without script blocks). Any help here? withCheckout is nowhere to be found the env variables are not set by default: pipeline { agent none stages { stage( 'checkout' ) { post { always { deleteDir() } } agent any steps { checkout([$class: 'GitSCM' , userRemoteConfigs: [[url: 'https: //github.com/docker/ for -linux.git' ]]]) sh 'set' } } } } trying to stuff into a withEnv block fails with `java.lang.UnsupportedOperationException: must specify $class with an implementation of interface java.util.List` pipeline { agent none stages { stage( 'checkout' ) { post { always { deleteDir() } } agent any steps { withEnv(checkout([$class: 'GitSCM' , userRemoteConfigs: [[url: 'https: //github.com/docker/ for -linux.git' ]]])) { sh 'set' } } } } } Jenkins ver. 2.219 (docker alpine installation) git 4.1.1 true git-client 3.1.1 true workflow-scm-step 2.10 true

          Mark Waite added a comment -

          nolange79 could you review the Jenkins Minute video "Using Git Environment Variables" and see if it resolves your issue?

          If it resolves your issue, then I'll add a git plugin documentation section on using the git plugin with Pipeline and will embed that video in the new section.

          Mark Waite added a comment - nolange79 could you review the Jenkins Minute video " Using Git Environment Variables " and see if it resolves your issue? If it resolves your issue, then I'll add a git plugin documentation section on using the git plugin with Pipeline and will embed that video in the new section.

          Norbert Lange added a comment -

          markewaite: No, video is generally a bad idea, and that specific one is not helping at all.

          Here is the problem in a single paragraph:

          checkout()
          // returns ""
          sh 'echo ${GIT_COMMIT}'
          // returns "null"
          echo "${env.GIT_COMMIT}"
          

          No environment variables are set.

          Norbert Lange added a comment - markewaite : No, video is generally a bad idea, and that specific one is not helping at all. Here is the problem in a single paragraph: checkout() // returns "" sh 'echo ${GIT_COMMIT}' // returns " null " echo "${env.GIT_COMMIT}" No environment variables are set.

          Mark Waite added a comment -

          nolange79 it looks to me like you're using declarative pipeline but then ignoring the default checkout which declarative pipeline provides for you, without explicitly stating that you intend to skip the default checkout. If you intend to skip the default checkout then you should extend your declarative pipeline with

          options {
              skipDefaultCheckout()
          }
          

          If you don't intend to skip the default checkout, then the techniques described in that video will work.

          If you intend to skip the default checkout, specify your own checkout, and use the return value from the checkout step to collect the settings used in the checkout, then it appears you'll need to use a script block in your declarative Pipeline. Refer to this example that I created while experimenting with the question. The example skips the default checkout, performs its own checkout, and assigns the return value of checkout() to the variable results. It then displays values from results.

          Mark Waite added a comment - nolange79 it looks to me like you're using declarative pipeline but then ignoring the default checkout which declarative pipeline provides for you, without explicitly stating that you intend to skip the default checkout. If you intend to skip the default checkout then you should extend your declarative pipeline with options { skipDefaultCheckout() } If you don't intend to skip the default checkout, then the techniques described in that video will work. If you intend to skip the default checkout, specify your own checkout, and use the return value from the checkout step to collect the settings used in the checkout, then it appears you'll need to use a script block in your declarative Pipeline. Refer to this example that I created while experimenting with the question. The example skips the default checkout, performs its own checkout, and assigns the return value of checkout() to the variable results . It then displays values from results .

          Mark Waite added a comment -

          nolange79 also, since this bug report is about the git step and not the checkout step, it would be better to use a different location for your question and for the answer to your question. When you ask a question in an issue, you limit the number of people that will answer the question to only those that are monitoring that bug. A question asked in the Jenkins mailing lists or the Jenkins chat channels can be seen by a much larger group.

          Mark Waite added a comment - nolange79 also, since this bug report is about the git step and not the checkout step, it would be better to use a different location for your question and for the answer to your question. When you ask a question in an issue, you limit the number of people that will answer the question to only those that are monitoring that bug. A question asked in the Jenkins mailing lists or the Jenkins chat channels can be seen by a much larger group.

          Norbert Lange added a comment - - edited

          Yeah, I posted the entire declarative pipeline couple posts before.

          I managed to get the variables with a script block, but I expected that there would be a way to get to this without breaking into scripting mode.

          What is a default checkout: where would the pipeline know the url from?
          Does withCheckout exist? its referenced in this thread.
          Would be nice to get withEnv working like I illustrated above.

          Docs send you completely in the wrong direction unfortunately.

          Edit: I replied here because this is often referenced as "answer"

          Norbert Lange added a comment - - edited Yeah, I posted the entire declarative pipeline couple posts before. I managed to get the variables with a script block, but I expected that there would be a way to get to this without breaking into scripting mode. What is a default checkout: where would the pipeline know the url from? Does withCheckout exist? its referenced in this thread. Would be nice to get withEnv working like I illustrated above. Docs send you completely in the wrong direction unfortunately. Edit: I replied here because this is often referenced as "answer"

          Mark Waite added a comment - - edited

          I managed to get the variables with a script block, but I expected that there would be a way to get to this without breaking into scripting mode.

          The variables are available if you don't use the checkout step in the declarative pipeline. The declarative pipeline has an implicit checkout step that happens before the Pipeline executes.

          What is a default checkout: where would the pipeline know the url from?

          When the Jenkinsfile for the Pipeline is read from SCM, the declarative pipeline uses that URL.

          Does withCheckout exist? its referenced in this thread.

          No, withCheckout does not exist. It was added to the scm step plugin May 5, 2017 and then removed on May 16, 2017.

          Docs send you completely in the wrong direction unfortunately.

          Which docs send you in the wrong direction?

          Mark Waite added a comment - - edited I managed to get the variables with a script block, but I expected that there would be a way to get to this without breaking into scripting mode. The variables are available if you don't use the checkout step in the declarative pipeline. The declarative pipeline has an implicit checkout step that happens before the Pipeline executes. What is a default checkout: where would the pipeline know the url from? When the Jenkinsfile for the Pipeline is read from SCM, the declarative pipeline uses that URL. Does withCheckout exist? its referenced in this thread. No, withCheckout does not exist. It was added to the scm step plugin May 5, 2017 and then removed on May 16, 2017 . Docs send you completely in the wrong direction unfortunately. Which docs send you in the wrong direction?

          Norbert Lange added a comment -

          "Which docs send you in the wrong direction?"

          Plain Pipelines using "inline Jenkinsfiles" seem to be largely ignored from all docs, similarly you often need to checkout multiple sources. If this is not explicitly mentioned, one would assume it works the same.
          The step returns a map of env variables already, so pushing those into withEnv would be a natural fit.

          That there is no "declarative" way to do this, is weird. I had many Problems with scripted pipelines, particularly when it comes to error handling (storing artifacts will silently fail, then cause an error at the end of the pipeline?) that I would want to stay clear of those.

          Norbert Lange added a comment - "Which docs send you in the wrong direction?" Plain Pipelines using "inline Jenkinsfiles" seem to be largely ignored from all docs, similarly you often need to checkout multiple sources. If this is not explicitly mentioned, one would assume it works the same. The step returns a map of env variables already, so pushing those into withEnv would be a natural fit. That there is no "declarative" way to do this, is weird. I had many Problems with scripted pipelines, particularly when it comes to error handling (storing artifacts will silently fail, then cause an error at the end of the pipeline?) that I would want to stay clear of those.

          Mark Waite added a comment -

          Thanks

          Mark Waite added a comment - Thanks

            abayer Andrew Bayer
            jglick Jesse Glick
            Votes:
            85 Vote for this issue
            Watchers:
            100 Start watching this issue

              Created:
              Updated:
              Resolved: