简体   繁体   中英

Cannot get build parameters in Jenkins Pipeline Job

I'm trying to get some build parameters in a Jenkins pipeline job. In this context the parameters are defined in the checkbox "this project is parameterized" and passed at build time.

In the job I call two branches:

parallel firstBranch: {
    build job: 'Run Blah', parameters: [string(name: 'BLAH', value: '$app.blah.blah')]

}, secondBranch: {
    build job: 'Run BlahBlah', parameters: [string(name: 'BLAH', value: '$app.blah.blah')]
}

I've tried accessing the build parameter: app.blah.blah in these various ways:

  • ${app.blah.blah}
  • $app.blah.blah
  • "${app.blah.blah}"
  • app.blah.blah
  • currentBuild.buildVariableResolver.resolve("app.blah.blah")
  • System.getenv("app.blah.blah")

I always get some exception that I can somewhat understand, but I'm starting to get very annoyed. It should not be this hard to get a build parameter in the script for God's sake. What am I doing wrong?

This is working for me:

println blah

So I guess it should be enough for you to do it like this:

parallel firstBranch: {
    build job: 'Run Blah', parameters: [string(name: 'BLAH', value: blah)]

}, secondBranch: {
    build job: 'Run BlahBlah', parameters: [string(name: 'BLAH', value: blah)]
}

Well, looks like you can't have dots in your build parameter names! Confuses Groovy into thinking you're accessing a class. Sucks that I won't be able to keep my parameters consistent across Ant scripts and Jenkins jobs, but it's not a huge deal right now. If anyone knows how to access dotted variables, please feel free to add input!

Correct syntax for build parameter variable: alphanumeric_underline_only

Correct syntax for accessing: println(alphanumeric_underline_only)

If your pipeline has parameter with the dot inside it name, you can try to get value of this parameter by using getProperty() , for example (tested):

//println params.MyApp.Api.Server // will not work
//println "${MyApp.Api.Server}" // will not work
println getProperty('MyApp.Api.Server') //works perfectly

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