简体   繁体   中英

Jenkins Pipeline build job parameter Syntax

I was wondering if anyone can explain the following Jenkins groovy syntax for build job and parameter . I could not find any documentation to explain it.

There's this + syntax at the end of the parameter block with a function, I am wondering if there function is supposed to return value to replace the original parameters? Or just add to them?

Function

def some_function(a, b) {
    build job: SomeJob,
    parameters: [
        string(name: 'p1', value: "..."),
        ...
    ] + some_other_function()
}

def some_other_function() {
    ...
    return some_value
}

The operator + here is to append an element to a list in Groovy. If you write println([1] + 2) in Groovy you will get [1, 2]. You may try this on https://www.jdoodle.com/execute-groovy-online/ .

And back to your original question, it's just to add the return value of some_other_function() to the parameters list. It's useful when you need to decide the parameters dynamically based on the job context. For example

def some_other_function() {
  return string(name: 'tag', value: 'master' == env.GIT_BRANCH ? 'release':'dev')
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM