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

Storing parent job/build in property

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Minor Minor
    • groovy-plugin
    • None

      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
              }
            }
          }
        }
      }

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

              Created:
              Updated: