Is there a 'getScriptPath()' equivalent for workflow pipeline?

12 views
Skip to first unread message

pallen

unread,
Feb 12, 2019, 11:54:30 AM2/12/19
to Jenkins Developers
Hi Guys,

With MultiBranch I can access the name of the Jenkinsfile script path from SCMSourceOwner()  e.g.

public String getScriptPathOrDefault() {
SCMSourceOwner owner = getOwner();
if (owner instanceof WorkflowMultiBranchProject) {
WorkflowMultiBranchProject branchProject = (WorkflowMultiBranchProject) owner;
WorkflowBranchProjectFactory branchProjectFactory = (WorkflowBranchProjectFactory) branchProject.getProjectFactory();
return branchProjectFactory.getScriptPath();
}
return "Jenkinsfile";
}

However from a Pipeline (workflow) I'm unable to find any way to access the name of the Jenkinsfile Script.

Ideally I would like to know the value during an SCM.checkout(...) perhaps via Run<?,?> run, probably from WorkflowJob or something.


Kind regards,
Paul

Steven F

unread,
Feb 12, 2019, 12:07:05 PM2/12/19
to Jenkins Developers
Looking at a script I wrote ages ago to parse a bunch of Jenkinsfiles, something like

FlowDefinition definition = job.getDefinition()
scriptPath = ((CpsScmFlowDefinition) definition).getScriptPath()

might point you in the right direction?

pallen

unread,
Feb 12, 2019, 12:57:07 PM2/12/19
to Jenkins Developers
Thank you; just what I was looking for.  I used...

((WorkflowRun) run).getParent().getDefinition().getScriptPath()
Reply all
Reply to author
Forward
0 new messages