-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
Jenkins ver. 2.73.2
java.runtime.version 1.8.0_171-b10
groovy-2.4.6
pipeline-build-step 2.5.1 true
pipeline-graph-analysis 1.5 true
pipeline-input-step 2.8 true
pipeline-milestone-step 1.3.1 true
pipeline-model-api 1.2.5 true
pipeline-model-declarative-agent 1.1.1 true
pipeline-model-definition 1.2.5 true
pipeline-model-extensions 1.2.5 true
pipeline-rest-api 2.9 true
pipeline-stage-step 2.3 true
pipeline-stage-tags-metadata 1.2.5 true
pipeline-stage-view 2.9 true
pipeline-utility-steps 1.5.1 true
windows-slaves 1.3.1 true
workflow-aggregator 2.5 true
workflow-api 2.26 true
workflow-basic-steps 2.6 true
workflow-cps 2.45 true
workflow-cps-global-lib 2.9 true
workflow-durable-task-step 2.17 true
workflow-job 2.15 true
workflow-multibranch 2.16 true
workflow-scm-step 2.6 true
workflow-step-api 2.14 true
workflow-support 2.18 true
Job runs on node with RHELJenkins ver. 2.73.2 java.runtime.version 1.8.0_171-b10 groovy-2.4.6 pipeline-build-step 2.5.1 true pipeline-graph-analysis 1.5 true pipeline-input-step 2.8 true pipeline-milestone-step 1.3.1 true pipeline-model-api 1.2.5 true pipeline-model-declarative-agent 1.1.1 true pipeline-model-definition 1.2.5 true pipeline-model-extensions 1.2.5 true pipeline-rest-api 2.9 true pipeline-stage-step 2.3 true pipeline-stage-tags-metadata 1.2.5 true pipeline-stage-view 2.9 true pipeline-utility-steps 1.5.1 true windows-slaves 1.3.1 true workflow-aggregator 2.5 true workflow-api 2.26 true workflow-basic-steps 2.6 true workflow-cps 2.45 true workflow-cps-global-lib 2.9 true workflow-durable-task-step 2.17 true workflow-job 2.15 true workflow-multibranch 2.16 true workflow-scm-step 2.6 true workflow-step-api 2.14 true workflow-support 2.18 true Job runs on node with RHEL
if (jobConfig.scm?.type in ['github', null]) { this.handleScmResponse = { // TODO: check why default values doesn't work script, state = '0', message = null -> logGithubTestStatus script, state, message } } else { this.handleScmResponse = { jobConfig, script, nameOfTest, state = null, message = null -> def currentMessage = message ?: stateMap[state] echo "State: ${state}, Message: ${currentMessage}" } } def logGithubTestStatus(script, String state = '0', message = '') { script.echo " ${message}" if (state == '-1') script.error "test failed" } def handleScmFromShell(script, String command) { def result = script.sh(script: command, returnStatus: true) this.handleScmResponse(script, result ? '-1' : '+1') }
Here we use default values for parameters in this.handleScmResponse closure. But if we call method handleScmFromShell which will call this.handleScmResponse closure which will call logGithubTestStatus method then we will get null values for state and message parameters in logGithubTestStatus.
Provided script will be loaded to main pipeline script using method load(). It appears defaults in pipelines that are loaded with the load() function with default parameters in closures never have the defaults resolved (so the default state = '0', for example, would actually be null).
Simple pipeline script to test an issue:
node 'master', { try { sh 'echo "def f = { x = [1] -> x += 1; x += 2; println x }\nf()\nf()\nprintln x\nreturn this" > test.groovy' load 'test.groovy' } finally { sh 'rm test.groovy' } }
The example output from a testing job:
[workspace] Running shell script + echo 'def f = { x = [1] -> x += 1; x += 2; println x } f() f() println x return this' [Pipeline] load [Pipeline] { (test.groovy) [Pipeline] } [Pipeline] // load [Pipeline] sh [workspace] Running shell script + rm test.groovy [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline java.lang.NullPointerException: Cannot execute null+1
- is blocked by
-
JENKINS-47166 new
- Resolved