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

Pipeline - plugin does not find SCMs on first execution

       This issue was reported by an user at github here.

      The issue is that the plugin is failing to getSCM in a pipeline run only on the first time, here is the code used by the plugin:

      Collection<? extends SCM> scms = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(projectAction.getProject()).getSCMs();
      

      scms is _ null _ when we run the pipeline script below, only for the first time:

       

      node() {
        def STOP_ON_ERROR = '';
        def mvnHome
        def javaHome
        def failed = false;
        try{
          stage('Preparation') { // for display purposes
            // Get the Maven tool.
            // ** NOTE: This 'M3' Maven tool must be configured
            // **       in the global configuration.
            checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/thomas-oo/eventAppFrontend']]])
          }
        }catch(Exception e){
          failed = true
          echo 'Build failed'
        }finally{
          if(!failed){
            stage('Last Changes'){
              echo 'In last changes'
              step([$class: 'LastChangesPublisher', format: 'LINE', matchWordsThreshold: '0.25', matching: 'NONE', matchingMaxComparisons: '1000', showFiles: true, synchronisedScroll: true, endRevision: ''])
            }
          }
          echo 'In finally block'
        }
      }

       

       

       

       

          [JENKINS-45720] Pipeline - plugin does not find SCMs on first execution

          Rafael Pestano created issue -
          Rafael Pestano made changes -
          Priority Original: Blocker [ 1 ] New: Major [ 3 ]
          Rafael Pestano made changes -
          Environment Original: Jenkins 2.19.1
          OpenJDK 1.8_102
          New: Jenkins 2.32
          OpenJDK 1.8_102
          Rafael Pestano made changes -
          Description Original: The plugin does not work in combination with a standard multibranch pipeline project. I have added a pipeline step for the LastChangesPublisher, which has been suggested by the snippet generator.

          My Jenkinsfile looks like:

          node('master') {
              stage('prep') {
                  checkout scm
                  step([$class: 'LastChangesPublisher', format: 'LINE', matchWordsThreshold: '0.25', matching: 'NONE', matchingMaxComparisons: '1000', showFiles: true, synchronisedScroll: true])
              }
          }

          My SCM system is Git and configured in the project configuration. As soon as Jenkins reaches the LastChangesPublisher step, the job exists with the following NPE:

          java.lang.NullPointerException
          at com.github.jenkins.lastchanges.LastChangesPublisher.perform(LastChangesPublisher.java:97)
          at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:69)
          at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:59)
          at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:52)
          at hudson.security.ACL.impersonate(ACL.java:221)
          at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:49)
          at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
          at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
          at java.lang.Thread.run(Thread.java:745)
          New:  This issues was reported by an user at [github here|[https://github.com/jenkinsci/last-changes-plugin/issues/4].]

           

          The issue is that the plugin is failing to getSCM in a pipeline run only on the first time, here is code used by the plugin:


          {code:java}
          Collection<? extends SCM> scms = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(projectAction.getProject()).getSCMs();
          {code}
          _*scms*_ is __ null __ when we run the pipeline script below, *only for the first time*:

           
          {noformat}
          node() {
            def STOP_ON_ERROR = '';
            def mvnHome
            def javaHome
            def failed = false;
            try{
              stage('Preparation') { // for display purposes
                // Get the Maven tool.
                // ** NOTE: This 'M3' Maven tool must be configured
                // ** in the global configuration.
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/thomas-oo/eventAppFrontend&#39;]]])
              }
            }catch(Exception e){
              failed = true
              echo 'Build failed'
            }finally{
              if(!failed){
                stage('Last Changes'){
                  echo 'In last changes'
                  step([$class: 'LastChangesPublisher', format: 'LINE', matchWordsThreshold: '0.25', matching: 'NONE', matchingMaxComparisons: '1000', showFiles: true, synchronisedScroll: true, endRevision: ''])
                }
              }
              echo 'In finally block'
            }
          }{noformat}
           

           

           

           
          Rafael Pestano made changes -
          Description Original:  This issues was reported by an user at [github here|[https://github.com/jenkinsci/last-changes-plugin/issues/4].]

           

          The issue is that the plugin is failing to getSCM in a pipeline run only on the first time, here is code used by the plugin:


          {code:java}
          Collection<? extends SCM> scms = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(projectAction.getProject()).getSCMs();
          {code}
          _*scms*_ is __ null __ when we run the pipeline script below, *only for the first time*:

           
          {noformat}
          node() {
            def STOP_ON_ERROR = '';
            def mvnHome
            def javaHome
            def failed = false;
            try{
              stage('Preparation') { // for display purposes
                // Get the Maven tool.
                // ** NOTE: This 'M3' Maven tool must be configured
                // ** in the global configuration.
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/thomas-oo/eventAppFrontend&#39;]]])
              }
            }catch(Exception e){
              failed = true
              echo 'Build failed'
            }finally{
              if(!failed){
                stage('Last Changes'){
                  echo 'In last changes'
                  step([$class: 'LastChangesPublisher', format: 'LINE', matchWordsThreshold: '0.25', matching: 'NONE', matchingMaxComparisons: '1000', showFiles: true, synchronisedScroll: true, endRevision: ''])
                }
              }
              echo 'In finally block'
            }
          }{noformat}
           

           

           

           
          New:  This issues was reported by an user at [github here|https://github.com/jenkinsci/last-changes-plugin/issues/4].

           

          The issue is that the plugin is failing to getSCM in a pipeline run only on the first time, here is code used by the plugin:
          {code:java}
          Collection<? extends SCM> scms = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(projectAction.getProject()).getSCMs();
          {code}
          _*scms*_ is _ _null_ _ when we run the pipeline script below, *only for the first time*:

           
          {noformat}
          node() {
            def STOP_ON_ERROR = '';
            def mvnHome
            def javaHome
            def failed = false;
            try{
              stage('Preparation') { // for display purposes
                // Get the Maven tool.
                // ** NOTE: This 'M3' Maven tool must be configured
                // ** in the global configuration.
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/thomas-oo/eventAppFrontend&#39;]]])
              }
            }catch(Exception e){
              failed = true
              echo 'Build failed'
            }finally{
              if(!failed){
                stage('Last Changes'){
                  echo 'In last changes'
                  step([$class: 'LastChangesPublisher', format: 'LINE', matchWordsThreshold: '0.25', matching: 'NONE', matchingMaxComparisons: '1000', showFiles: true, synchronisedScroll: true, endRevision: ''])
                }
              }
              echo 'In finally block'
            }
          }{noformat}
           

           

           

           
          Rafael Pestano made changes -
          Description Original:  This issues was reported by an user at [github here|https://github.com/jenkinsci/last-changes-plugin/issues/4].

           

          The issue is that the plugin is failing to getSCM in a pipeline run only on the first time, here is code used by the plugin:
          {code:java}
          Collection<? extends SCM> scms = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(projectAction.getProject()).getSCMs();
          {code}
          _*scms*_ is _ _null_ _ when we run the pipeline script below, *only for the first time*:

           
          {noformat}
          node() {
            def STOP_ON_ERROR = '';
            def mvnHome
            def javaHome
            def failed = false;
            try{
              stage('Preparation') { // for display purposes
                // Get the Maven tool.
                // ** NOTE: This 'M3' Maven tool must be configured
                // ** in the global configuration.
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/thomas-oo/eventAppFrontend&#39;]]])
              }
            }catch(Exception e){
              failed = true
              echo 'Build failed'
            }finally{
              if(!failed){
                stage('Last Changes'){
                  echo 'In last changes'
                  step([$class: 'LastChangesPublisher', format: 'LINE', matchWordsThreshold: '0.25', matching: 'NONE', matchingMaxComparisons: '1000', showFiles: true, synchronisedScroll: true, endRevision: ''])
                }
              }
              echo 'In finally block'
            }
          }{noformat}
           

           

           

           
          New:  This issues was reported by an user at [github here|https://github.com/jenkinsci/last-changes-plugin/issues/4].

           

          The issue is that the plugin is failing to getSCM in a pipeline run only on the first time, [here is the code|https://github.com/jenkinsci/last-changes-plugin/blob/b6d36262b26c55f7cee94ee06f818a8e408bfaea/src/main/java/com/github/jenkins/lastchanges/LastChangesPublisher.java#L102] used by the plugin:
          {code:java}
          Collection<? extends SCM> scms = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(projectAction.getProject()).getSCMs();
          {code}
          _*scms*_ is _ _null_ _ when we run the pipeline script below, *only for the first time*:

           
          {noformat}
          node() {
            def STOP_ON_ERROR = '';
            def mvnHome
            def javaHome
            def failed = false;
            try{
              stage('Preparation') { // for display purposes
                // Get the Maven tool.
                // ** NOTE: This 'M3' Maven tool must be configured
                // ** in the global configuration.
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/thomas-oo/eventAppFrontend&#39;]]])
              }
            }catch(Exception e){
              failed = true
              echo 'Build failed'
            }finally{
              if(!failed){
                stage('Last Changes'){
                  echo 'In last changes'
                  step([$class: 'LastChangesPublisher', format: 'LINE', matchWordsThreshold: '0.25', matching: 'NONE', matchingMaxComparisons: '1000', showFiles: true, synchronisedScroll: true, endRevision: ''])
                }
              }
              echo 'In finally block'
            }
          }{noformat}
           

           

           

           

          Hi batmat, danielbeck and oleg_nenashev,

           

          Do you have any recomendation on this? I've read the pipeline devguide but missed a concrete example, do you have any pointers on that?

           

          Thanks in advance!

          Rafael Pestano added a comment - Hi batmat , danielbeck and oleg_nenashev ,   Do you have any recomendation on this? I've read the pipeline devguide but missed a concrete example, do you have any pointers on that?   Thanks in advance!
          Rafael Pestano made changes -
          Description Original:  This issues was reported by an user at [github here|https://github.com/jenkinsci/last-changes-plugin/issues/4].

           

          The issue is that the plugin is failing to getSCM in a pipeline run only on the first time, [here is the code|https://github.com/jenkinsci/last-changes-plugin/blob/b6d36262b26c55f7cee94ee06f818a8e408bfaea/src/main/java/com/github/jenkins/lastchanges/LastChangesPublisher.java#L102] used by the plugin:
          {code:java}
          Collection<? extends SCM> scms = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(projectAction.getProject()).getSCMs();
          {code}
          _*scms*_ is _ _null_ _ when we run the pipeline script below, *only for the first time*:

           
          {noformat}
          node() {
            def STOP_ON_ERROR = '';
            def mvnHome
            def javaHome
            def failed = false;
            try{
              stage('Preparation') { // for display purposes
                // Get the Maven tool.
                // ** NOTE: This 'M3' Maven tool must be configured
                // ** in the global configuration.
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/thomas-oo/eventAppFrontend&#39;]]])
              }
            }catch(Exception e){
              failed = true
              echo 'Build failed'
            }finally{
              if(!failed){
                stage('Last Changes'){
                  echo 'In last changes'
                  step([$class: 'LastChangesPublisher', format: 'LINE', matchWordsThreshold: '0.25', matching: 'NONE', matchingMaxComparisons: '1000', showFiles: true, synchronisedScroll: true, endRevision: ''])
                }
              }
              echo 'In finally block'
            }
          }{noformat}
           

           

           

           
          New:  This issue was reported by an user at [github here|https://github.com/jenkinsci/last-changes-plugin/issues/4].

          The issue is that the plugin is failing to getSCM in a pipeline run only on the first time, [here is the code|https://github.com/jenkinsci/last-changes-plugin/blob/b6d36262b26c55f7cee94ee06f818a8e408bfaea/src/main/java/com/github/jenkins/lastchanges/LastChangesPublisher.java#L102] used by the plugin:
          {code:java}
          Collection<? extends SCM> scms = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(projectAction.getProject()).getSCMs();
          {code}
          _*scms*_ is _ _null_ _ when we run the pipeline script below, *only for the first time*:

           
          {noformat}
          node() {
            def STOP_ON_ERROR = '';
            def mvnHome
            def javaHome
            def failed = false;
            try{
              stage('Preparation') { // for display purposes
                // Get the Maven tool.
                // ** NOTE: This 'M3' Maven tool must be configured
                // ** in the global configuration.
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/thomas-oo/eventAppFrontend&#39;]]])
              }
            }catch(Exception e){
              failed = true
              echo 'Build failed'
            }finally{
              if(!failed){
                stage('Last Changes'){
                  echo 'In last changes'
                  step([$class: 'LastChangesPublisher', format: 'LINE', matchWordsThreshold: '0.25', matching: 'NONE', matchingMaxComparisons: '1000', showFiles: true, synchronisedScroll: true, endRevision: ''])
                }
              }
              echo 'In finally block'
            }
          }{noformat}
           

           

           

           
          Rafael Pestano made changes -
          Description Original:  This issue was reported by an user at [github here|https://github.com/jenkinsci/last-changes-plugin/issues/4].

          The issue is that the plugin is failing to getSCM in a pipeline run only on the first time, [here is the code|https://github.com/jenkinsci/last-changes-plugin/blob/b6d36262b26c55f7cee94ee06f818a8e408bfaea/src/main/java/com/github/jenkins/lastchanges/LastChangesPublisher.java#L102] used by the plugin:
          {code:java}
          Collection<? extends SCM> scms = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(projectAction.getProject()).getSCMs();
          {code}
          _*scms*_ is _ _null_ _ when we run the pipeline script below, *only for the first time*:

           
          {noformat}
          node() {
            def STOP_ON_ERROR = '';
            def mvnHome
            def javaHome
            def failed = false;
            try{
              stage('Preparation') { // for display purposes
                // Get the Maven tool.
                // ** NOTE: This 'M3' Maven tool must be configured
                // ** in the global configuration.
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/thomas-oo/eventAppFrontend&#39;]]])
              }
            }catch(Exception e){
              failed = true
              echo 'Build failed'
            }finally{
              if(!failed){
                stage('Last Changes'){
                  echo 'In last changes'
                  step([$class: 'LastChangesPublisher', format: 'LINE', matchWordsThreshold: '0.25', matching: 'NONE', matchingMaxComparisons: '1000', showFiles: true, synchronisedScroll: true, endRevision: ''])
                }
              }
              echo 'In finally block'
            }
          }{noformat}
           

           

           

           
          New:  This issue was reported by an user at [github here|https://github.com/jenkinsci/last-changes-plugin/issues/4].

          The issue is that the plugin is failing to getSCM in a pipeline run only on the first time, [here is the code|https://github.com/jenkinsci/last-changes-plugin/blob/d809e2044c6d97b7036ed566e47c1420bb84d85c/src/main/java/com/github/jenkins/lastchanges/LastChangesPublisher.java#L109] used by the plugin:
          {code:java}
          Collection<? extends SCM> scms = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(projectAction.getProject()).getSCMs();
          {code}
          _*scms*_ is _ _null_ _ when we run the pipeline script below, *only for the first time*:

           
          {noformat}
          node() {
            def STOP_ON_ERROR = '';
            def mvnHome
            def javaHome
            def failed = false;
            try{
              stage('Preparation') { // for display purposes
                // Get the Maven tool.
                // ** NOTE: This 'M3' Maven tool must be configured
                // ** in the global configuration.
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/thomas-oo/eventAppFrontend&#39;]]])
              }
            }catch(Exception e){
              failed = true
              echo 'Build failed'
            }finally{
              if(!failed){
                stage('Last Changes'){
                  echo 'In last changes'
                  step([$class: 'LastChangesPublisher', format: 'LINE', matchWordsThreshold: '0.25', matching: 'NONE', matchingMaxComparisons: '1000', showFiles: true, synchronisedScroll: true, endRevision: ''])
                }
              }
              echo 'In finally block'
            }
          }{noformat}
           

           

           

           

          I think it is more an issue in workflow-job plugin rather than in consumer plugins. I'm hitting the same problem with bitbucket-build-status-notifier, there is no reasonable way to retrieve the SCMs of the already performed checkouts in the first build. It's really painful specially when using branch source plugins.

          WorkflobJob getSCMs method could fallback to the SCM from checkouts in the current build if there is no last completed build. WorkflowRun class already has this information but it's not accessible to external classes.

           

           

           

           

          Luis Piedra-Márquez added a comment - I think it is more an issue in workflow-job plugin rather than in consumer plugins. I'm hitting the same problem with bitbucket-build-status-notifier, there is no reasonable way to retrieve the SCMs of the already performed checkouts in the first build. It's really painful specially when using branch source plugins. WorkflobJob getSCMs method could fallback to the SCM from checkouts in the current build if there is no last completed build. WorkflowRun class already has this information but it's not accessible to external classes.        

            rmpestano Rafael Pestano
            rmpestano Rafael Pestano
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: