Home > Mobile >  Jenkins Pipeline build job parameter Syntax
Jenkins Pipeline build job parameter Syntax

Time:06-04

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
}

CodePudding user response:

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')
}
  • Related