Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-49794

Parameter references not using params.NAME retained across Replay

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • workflow-cps-plugin
    • None

      My pipeline defines a parameter with sth like:

       

      parameters {
       booleanParam(name: 'RUN_TESTS', defaultValue: false, description: 'Do you want to run the build with tests?')
       }

       

      Printing the param value with

      script {
       if (params.RUN_TESTS) {
       echo "true: $RUN_TESTS"
       }
       else echo "false: $RUN_TESTS"
       }

      shows that the value is always TRUE and the tests are always executed.

       I think this is somewhat related to https://issues.jenkins-ci.org/browse/JENKINS-36543 

       

       

          [JENKINS-49794] Parameter references not using params.NAME retained across Replay

          valentina armenise created issue -
          valentina armenise made changes -
          Component/s New: workflow-job-plugin [ 21716 ]
          valentina armenise made changes -
          Description Original: My pipeline defines a parameter with sth like:

           

           
          {noformat}
          parameters {
           booleanParam(name: 'RUN_TESTS', defaultValue: false, description: 'Do you want to run the build with tests?')
           }{noformat}
           

           

          Printing the param value with
          {code:java}
          script {
           if (params.RUN_TESTS) {
           echo "true: $RUN_TESTS"
           }
           else echo "false: $RUN_TESTS"
           }{code}
          shows that the value is always TRUE and the tests are always executed.

           

          I think this is somewhat related to 

          I think this is somewhat related to https://issues.jenkins-ci.org/browse/JENKINS-36543 

           

           
          New: My pipeline defines a parameter with sth like:

           
          {noformat}
          parameters {
           booleanParam(name: 'RUN_TESTS', defaultValue: false, description: 'Do you want to run the build with tests?')
           }{noformat}
           

          Printing the param value with
          {code:java}
          script {
           if (params.RUN_TESTS) {
           echo "true: $RUN_TESTS"
           }
           else echo "false: $RUN_TESTS"
           }{code}
          shows that the value is always TRUE and the tests are always executed.

           I think this is somewhat related to https://issues.jenkins-ci.org/browse/JENKINS-36543 

           

           
          valentina armenise made changes -
          Attachment New: Screen Shot 2018-02-28 at 15.12.16.png [ 41626 ]

          plugin versions are attached as screenshot

          valentina armenise added a comment - plugin versions are attached as screenshot

          Andrew Bayer added a comment - - edited

          Hrm, I can't reproduce this running the following:

          pipeline {
              agent any
              parameters {
                  booleanParam(name: 'RUN_TESTS', defaultValue: false, description: 'Do you want to run the build with tests?')
              }
              stages {
                  stage('foo') {
                      steps {
                          script {
                              if (params.RUN_TESTS) {
                                  echo "true: ${params.RUN_TESTS}"
                              }
                              else echo "false: ${params.RUN_TESTS}"
                          }            
                      }
                  }
              }
          }
          

          Andrew Bayer added a comment - - edited Hrm, I can't reproduce this running the following: pipeline { agent any parameters { booleanParam(name: 'RUN_TESTS' , defaultValue: false , description: 'Do you want to run the build with tests?' ) } stages { stage( 'foo' ) { steps { script { if (params.RUN_TESTS) { echo " true : ${params.RUN_TESTS}" } else echo " false : ${params.RUN_TESTS}" } } } } }

          mm I could reproduce when hitting on REPLAY (as opposite of starting a new build). Can it make any difference? I can do some more tests

          valentina armenise added a comment - mm I could reproduce when hitting on REPLAY (as opposite of starting a new build). Can it make any difference? I can do some more tests

          Ok I can reproduce it in this way.

           

          • create the pipeline job and set the default to true.
          • hit on REPLAY but in the script section, modify the default to false
          • execute

          valentina armenise added a comment - Ok I can reproduce it in this way.   create the pipeline job and set the default to true. hit on REPLAY but in the script section, modify the default to false execute

          Andrew Bayer added a comment -

          Aaaaah, ok, I think I know what's happening here. When you replay the build with job parameter definitions already in place, that results in the run actually having those parameters as part of it - so params.RUN_TESTS in the replayed build isn't getting the default value as it is in the first build, it's getting the actual value of the parameter RUN_TESTS. And that actual value is true, since that was the default value for RUN_TESTS when the build started.

          Andrew Bayer added a comment - Aaaaah, ok, I think I know what's happening here. When you replay the build with job parameter definitions already in place, that results in the run actually having those parameters as part of it - so params.RUN_TESTS in the replayed build isn't getting the default value as it is in the first build, it's getting the actual value of the parameter RUN_TESTS . And that actual value is true, since that was the default value for RUN_TESTS when the build started.

          yeah makes sense but it's not ideal. Is there something we can do or you think it's a non-defect? It makes testing harder

          valentina armenise added a comment - yeah makes sense but it's not ideal. Is there something we can do or you think it's a non-defect? It makes testing harder

            Unassigned Unassigned
            varmenise valentina armenise
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: