jenkinsci / jms-messaging-plugin

https://plugins.jenkins.io/jms-messaging
12 stars 38 forks source link

Boolean parameters are not propogated to pipeline DSL when job is triggered by a message #134

Closed mherbert25 closed 5 years ago

mherbert25 commented 5 years ago

I recently upgraded plugins on my Jenkins master:

Credentials Plugin: 2.1.18 --> 2.1.19 Git client plugin: 2.7.6 --> 2.7.7 Git plugin: 3.9.1 --> 3.10.0 GitLab Plugin: 1.5.9 --> 1.5.12 JMS Messaging Plugin: 1.1.2 --> 1.1.8 Pipeline: SCM Step: 2.7 --> 2.9 Pipeline: Step API: 2.19 --> 2.20 Pipeline: Supporting APIs: 3.2 --> 3.3 Script Security Plugin: 1.56 --> 1.60

After the upgrade, my pipeline job started failing with the following exception:

groovy.lang.MissingPropertyException: No such property: dryrun for class: WorkflowScript
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:458)
    at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.getProperty(DefaultInvoker.java:39)
    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
    at WorkflowScript.run(WorkflowScript:70)

NOTE: WorkflowScript line 70 is the first time I try to access $dryrun in the shell script within the DSL.

The missing parameter 'dryrun' is a boolean parameter that is defaulted to 'false'. It turns out the failure only happens when the job is triggered by message bus. If I trigger it manually, it works fine. This is what leads me to believe that it is the jms-messaging-plugin which is causing the issue. I've also printed the env in the shell scirpt and all boolean params are missing, but other params are present.

As a workaround, I can recreate the parameter 'dryrun' as a string instead of a boolean, and everything works fine.

Here is a snippet of my DSL which may help in reproducing the problem:

        stages {
                stage('RUN') {
                    steps {
                        script {
                            sh "rm -f ${env.RESULT_FILE}"
                            def msg = jsonParse(env.CI_MESSAGE)
                            env.ERRATA_ID = msg.errata_id
                        }
                        withCredentials(
                            [
                                file(credentialsId: '<changed_to_protect_the_innocent>', variable: 'SECRET1'),
                                file(credentialsId: '<changed_to_protect_the_innocent>', variable: 'SECRET2')
                            ]) {
                                sh """
                                    echo MESSAGE_HEADERS=\$MESSAGE_HEADERS
                                    echo CI_MESSAGE=\$CI_MESSAGE
                                    set +x
                                    ARGS=\"\$ARGS --errata-url $ERRATA_URL\"
                                    ARGS=\"\$ARGS --brew-url $BREW_URL\"
                                    ARGS=\"\$ARGS --output-file $RESULT_FILE\"
                                    [ \"$dryrun\" = \"true\" ] && ARGS=\"\$ARGS --dry\"
                                    [ \"$debug\" = \"true\" ] && ARGS=\"\$ARGS --debug\"
                                    [ -n \"$output_dir\" ] && ARGS=\"\$ARGS --output-dir \$output_dir\"
                                    set -x
                                    \$JENKINS_HOME/script.py $ERRATA_ID \$ARGS
                                """
                        }
                    }
                }
scoheb commented 5 years ago

Thanks for reporting. I am investigating...

scoheb commented 5 years ago

@mherbert25 snapshot version available here with fix: https://ci.jenkins.io/job/Plugins/job/jms-messaging-plugin/job/PR-135/2/artifact/target/jms-messaging.hpi