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

          [JENKINS-48508] Storing parent job/build in property

          Jakub Pawlinski created issue -
          Jakub Pawlinski made changes -
          Description Original: 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 \{
                          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
                      }
          }
          }
          }
          New: I want to be able to access parent job/build from my pipeline, unfortunately it throws an error.

           
          {code:java}
          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 {
                          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
                      }
          }
          }
          }
          {code}
          Jakub Pawlinski made changes -
          Description Original: I want to be able to access parent job/build from my pipeline, unfortunately it throws an error.

           
          {code:java}
          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 {
                          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
                      }
          }
          }
          }
          {code}
          New: I want to be able to access parent job/build from my pipeline, unfortunately it throws an error.

           
          {code:java}
          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 {
                  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
                      }
          }
          }
          }
          {code}
          Jakub Pawlinski made changes -
          Description Original: I want to be able to access parent job/build from my pipeline, unfortunately it throws an error.

           
          {code:java}
          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 {
                  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
                      }
          }
          }
          }
          {code}
          New: I want to be able to access parent job/build from my pipeline, unfortunately it throws an error.

           
          {code:java}
          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 {
                  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
                }
              }
            }
          }
          {code}
          Jakub Pawlinski made changes -
          Description Original: I want to be able to access parent job/build from my pipeline, unfortunately it throws an error.

           
          {code:java}
          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 {
                  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
                }
              }
            }
          }
          {code}
          New: I want to be able to access parent job/build from my pipeline, unfortunately it throws an error.

           
          {code:java}
          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
                  }
               }
              }
            }
          }{code}

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

              Created:
              Updated: