Basically I can't pass build properties to Library var call without extra nonsense.
jenkinsfile relevant chunk:
tc_test{
repo = 'test1'
folder = 'test2'
submodules = true
refs = params.GitCheckout
}
That results in error
java.lang.NullPointerException: Cannot get property 'GitCheckout' on null object
This, however, works:
def a1 = params.GitCheckout
tc_test{
repo = 'test1'
folder = 'test2'
submodules = true
refs = a1
}
The contents of the vars/tc_test.groovy in shared library :
def call ( body ) {
def config = [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
try {
body()
} catch(e) {
currentBuild.result = "FAILURE";
throw e;
} finally {
config.each{ k, v -> println "${k}:${v}" }
}
}
I'm not really good with groovy, so it might be something obvious.
What is a Shared Library in Jenkins? A shared library is a collection of independent Groovy scripts which you pull into your Jenkinsfile at runtime. The best part is, the Library can be stored, like everything else, in a Git repository. This means you can version, tag, and do all the cool stuff you're used to with Git.
What's a Jenkins Multibranch Pipeline? A multibranch job is simply a folder of pipeline jobs. For every branch you have, Jenkins will create a folder. So instead of creating a pipeline job for each of the branches you have in a git repository, you could use a multibranch job.
Got the answer from Jenkins JIRA.
Small workaround is using maps instead of closures:
tc_test ([
repo: 'test1',
folder: 'test2',
submodules: true,
refs = params.GitCheckout
])
May have drawbacks, but for me that worked perfectly.
Still have to transfer params as argument to have access to them, but at least the code makes more sense now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With