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

Cannot get RestartDeclarativePipelineCause origin run number and stage name by using RunWrapper.getBuildCauses

XMLWordPrintable

      The org.jenkinsci.plugins.pipeline.modeldefinition.causes.RestartDeclarativePipelineCause doesn't set @Exported visibility for the getOriginRunNumber and getOriginStage methods, so it is impossible to read values by using Jenkins declarative API: currentBuild.getBuildCauses().

      pipeline {
          agent {
              label 'tiny'
          }
          stages {
              stage('One') {
                  steps {
                      echo 'one'
                  }
              }
              stage('Two') {
                  steps {
                      echo 'two'
                      script {
                          currentBuild.getBuildCauses().each {
                              echo "${it}"
                          }
                      }
                  }
              }
          }
      }
      

      Output when restarted from Stage:

      [...]
      12:02:38  [Pipeline] echo
      12:02:38  [_class:hudson.model.Cause$UserIdCause, shortDescription:Started by user Gabrys, Adam, userId:SECRET, userName:Gabrys, Adam]
      12:02:38  [Pipeline] echo
      12:02:38  [_class:org.jenkinsci.plugins.pipeline.modeldefinition.causes.RestartDeclarativePipelineCause, shortDescription:Restarted from build #13, stage One]
      [...]
      

      As you see Cause$UserIdCause exported all fields and RestartDeclarativePipelineCause only the short description (I don't want to parse string which btw. could be localized).

            Unassigned Unassigned
            agabrys Adam Gabryś
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: