if (agentLabel==null) { agent any } else { agent {label "${agentLabel}"} } .... rest of the pipeline }
Mario Jauvin
unread,
Dec 30, 2019, 8:53:12 AM12/30/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Jenkins Users
This seems to be the only way that I can get it working but it requires repeating the pipeline twice which in my case is a complicated one:
def call(String buildType, String agentLabel=null) { if ("versionBranch".equals(buildType)) {
if (agentLabel==null) { pipeline { agent any ... rest of the pipeline } } else { pipeline { agent {label "${agentLabel}"} ... rest of the pipeline } } } }
Is there another way?
Mario Jauvin
unread,
Dec 30, 2019, 10:34:18 AM12/30/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Jenkins Users
Would there be a way to create a groovy variable named agentObject that either contains the object {label "$agentLabel"} or the object any provided by the pipeline namespace and use a syntax like: agent $agentObject?