terinary operators in declared pipeline

20 views
Skip to first unread message

Rita Morgan

unread,
Jun 1, 2022, 12:48:02 PM6/1/22
to Jenkins Users
I know you can do terninary operations.  Is it possible to chain them?

so,
if branch = "main" ? "@daily":""
if branch = "master" ?" @hourly":""
and so on?


Message has been deleted
Message has been deleted

Martin Schmude

unread,
Jun 2, 2022, 3:18:43 PM6/2/22
to Jenkins Users
You can code
def result = (branch == "main" 
              ? "@daily" 
              : (branch == "master" 
                ? "@hourly" 
                : ""))

Maybe you find a switch more readable:
def result
switch(branch) {
    case "main":
        result = "@daily"
        break
    case "master":
        result = "@hourly"
        break
    default:
        result = ""
}
Reply all
Reply to author
Forward
0 new messages