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

Storing parent job/build in property

    Details

    • Similar Issues:

      Description

      I want to be able to access parent job/build from my pipeline, unfortunately it throws an error.

       

      import org.jenkinsci.plugins.workflow.job.WorkflowJob
      import org.jenkinsci.plugins.workflow.job.WorkflowRun
      
      WorkflowJob ParentJob
      WorkflowRun ParentBuild
      
      pipeline {
        agent any
        stages {
          stage('Run') {
            steps {
              script {
                def cause = currentBuild.rawBuild.getCause(hudson.model.Cause$UpstreamCause)
                if (cause == null) {
                  currentBuild.result = 'ABORTED'
                  error("Unknown parent build or current build was triggered by user directly.")
                }
                def parentJob = hudson.model.Hudson.instance.getItem(cause.upstreamProject)
                def parentBuild = parentJob.getBuildByNumber(cause.upstreamBuild)
                      
                ParentJob = parentJob
                ParentBuild = parentBuild
              }
            }
          }
        }
      }

        Attachments

          Activity

          There are no comments yet on this issue.

            People

            • Assignee:
              vjuranek vjuranek
              Reporter:
              quas Jakub Pawlinski
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: