I my pipeline I use properties of ParentJob (the job that triggered current 
job) multiple times.

I wrote script to evaluate it, but it order to do this only once, I wanted 
to store it in property outside pipeline, unfortunately this 
brings NotSerializableException regardless that it actually works.

Maybe you have some ideas, my simplified pipeline:

1. pipeline TestScriptRunner, pipelinescript:
build 'TestScript'

2. pipeline TestScript, pipelinescript:
import jenkins.model.Jenkins
import java.text.*
import org.jenkinsci.plugins.workflow.job.WorkflowJob
import org.jenkinsci.plugins.workflow.job.WorkflowRun

WorkflowJob ParentJob

pipeline {
agent {
node {
label params.NODE
}
}

stages {
stage ('Initialise properties') {
steps {
echo "Evaluating parent job"
script {
def cause = currentBuild.rawBuild.getCause(hudson.model.Cause$UpstreamCause)
if (cause == null) {
bat """
@ECHO Error: Unknown parent build or current build was triggered by user 
directly.
@EXIT 1
"""
}

def parentJob = hudson.model.Hudson.instance.getItem(cause.upstreamProject)

//below works fine
echo "Located parent job:\t${parentJob.getFullDisplayName()}"

//below causes the NotSerializableException 
ParentJob = parentJob

//below works fine, but there is exception waiting for being thrown at the 
end of the pipeline
echo "Property ParentJob:\t${ParentJob.getFullDisplayName()}"
}
}
}
}
}

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/b17809cc-d6e2-472c-ad39-e6b92fae9399%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to