jenkinsfile-runner icon indicating copy to clipboard operation
jenkinsfile-runner copied to clipboard

Question: Boolean parameters?

Open henryborchers opened this issue 4 years ago • 4 comments

Can I use --arg with boolean parameters? I can only seem to get it work with string parameters. I've tried "-a BUILD_PACKAGE=true" but evaluates to the string, "true", instead of the boolean value, true.

henryborchers avatar Sep 24 '20 13:09 henryborchers

Yes, there is a bug in the current implementation: https://github.com/jenkinsci/jenkinsfile-runner/blob/cb3db2e29f470b807dfe5b68432021e060c32312/payload/src/main/java/io/jenkins/jenkinsfile/runner/Runner.java#L81-L87

Ideally the code should retrieve String Parameter Definitions from type declarations and then invoke createValue commands (Javadoc). The challenge with that is that we do not have StringParameterDefinition objects until the Pipeline is executed. Fetching this data would require changes on the Pipeline side so that we can fetch the data before Pipeline runs. Easy (and supported?) for Declarative Pipeline, more difficult for Scripted.

As an alternative, it would be possible to support explicit specification of argument types in the Jenkinsfile Runner CLI arguments

oleg-nenashev avatar Sep 24 '20 13:09 oleg-nenashev

As an alternative, it would be possible to support explicit specification of argument types in the Jenkinsfile Runner CLI arguments

Oddly enough, I actually like that better. It's more explicit.

henryborchers avatar Sep 24 '20 13:09 henryborchers

For example: --arg BUILD_PACKAGE=boolean:true

henryborchers avatar Sep 24 '20 13:09 henryborchers

Oddly enough, I actually like that better. It's more explicit.

Yes, it is also easier to implement such alternative.

It might become a bit more challenging with other parameter types coming from plugins. It should be still doable using a @Symbol annotation with name or a full class name for parameter definitions without symbols defined.

oleg-nenashev avatar Sep 24 '20 13:09 oleg-nenashev