Closed anbrsap closed 5 years ago
It was released in https://github.com/jenkinsci/jenkinsfile-runner/releases/tag/1.0-beta-10 . Thanks @anbrsap !
[Pipeline] Start of Pipeline [Pipeline] node Running on Jenkins in C:\ProgramData\Jenkins.jenkins\workspace\create-issue [Pipeline] { [Pipeline] withEnv [Pipeline] { [Pipeline] stage [Pipeline] { (Deploy Version to Jira) [Pipeline] script [Pipeline] { [Pipeline] jiraGetVersion WARNING: Unknown parameter(s) found for class type 'org.thoughtslive.jenkins.plugins.jira.steps.GetVersionStep': credentialsId,idOrKey Error Code: -1 Error Message: id is empty or null. [Pipeline] } [Pipeline] // script [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: id is empty or null. Finished: FAILURE
Problem
Jenkinsfile Runner has a
--arg
option to pass parameters to the pipeline. The value of a parameter may be a zero-length string:In such case the respective
StringParameterValue
in the job'sParametersAction
will have its value set tonull
. This is different from the behavior of a pipeline job with parameters in a classical Jenkins, where the value is nevernull
but a zero-length string if no default value has been defined via the respectiveStringParameterDefinition
). As a consequence pipelines running successfully in a classical Jenkins may break when executed with Jenkinsfile Runner, for instance inhudson.model.StringParameterValue#buildEnvironment()
How to reproduce
Create a directory
testcase
with aJenkinsfile
having the following contents:Change into directory
testcase
and run the pipeline via Jenkinsfile Runner:Remark 1: Setting the system property
hudson.model.ParametersAction.keepUndefinedParameters=true
is required to include all parameters into the environment of pipeline steps like it is done with classical pipeline jobs having expected parameters declared viaParametersDefinitionProperty
.Remark 2: The Docker image
ppiper/jenkinsfile-runner
may be replaced by your own Jenkinsfile Runner image. You may also run the testcase without Docker if you have a Jenkinsfile Runner available on your machine.Output:
Expected result:
Analysis
The Jenkinsfile Runner uses args4j to parse its arguments (see the Bootstrap class).
For the
--arg
option args4j uses the MapOptionHandler, which converts empty string values tonull
.The Jenkinsfile Runner's Runner class passes the parsed key-value pairs from the
--arg
options - with the value possibly beingnull
- asStringParameterValue
s in aParametersAction
into the pipeline job.Proposed Solution
The
postConstruct()
method of Jenkinsfile Runner's Bootstrap class should replace allnull
values in mapthis.workflowParameters
by zero-length strings.