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

Parameter references not using params.NAME retained across Replay

    XMLWordPrintable

Details

    Description

      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 

       

       

      Attachments

        Activity

          So say I run a build without specifying parameters, it takes the default ones. Then I replay the same but I modify the script to have different default parameters. From a user perspective it s confusing if it does not take the new default values.

          Maybe there should be condition for which if the replayed run was using the default parameters, those have to be computed again as the script may have changed.

          In any case it s a minor, I let you decide if to close it or put it lowest priority. 

           

          varmenise valentina armenise added a comment - So say I run a build without specifying parameters, it takes the default ones. Then I replay the same but I modify the script to have different default parameters. From a user perspective it s confusing if it does not take the new default values. Maybe there should be condition for which if the replayed run was using the default parameters, those have to be computed again as the script may have changed. In any case it s a minor, I let you decide if to close it or put it lowest priority.   

          The way I use the Replay feature is to work through changes to my Jenkinsfile without committing a bunch of intermediate changes that may or may not work. 

          I think the best way to "improve" this would be to add the parameters to the top of the replay page, as if I had clicked "build with parameters". 

          I thought a workaround might be to go into the configuration of that pipeline and either delete the parameter or change its value. In my case, the pipeline is part of a multibranch pipeline and doesn't allow me to save changes to the pipeline.

          If this isn't a feature, there should at least be a workaround...

          dwatroustrinet Daniel Watrous added a comment - The way I use the Replay feature is to work through changes to my Jenkinsfile without committing a bunch of intermediate changes that may or may not work.  I think the best way to "improve" this would be to add the parameters to the top of the replay page, as if I had clicked "build with parameters".  I thought a workaround might be to go into the configuration of that pipeline and either delete the parameter or change its value. In my case, the pipeline is part of a multibranch pipeline and doesn't allow me to save changes to the pipeline. If this isn't a feature, there should at least be a workaround...

          I also tried going in to the config.xml for that job and manually removing the parameters

          <hudson.model.BooleanParameterDefinition>
           <name>myParameter</name>
           <description>Set to true if you want to live</description>
           <defaultValue>true</defaultValue>
           </hudson.model.BooleanParameterDefinition>

          They were rewritten with the updated default value, but the build still ignores the default value and uses whatever the parameters were for that last build. I can't find a workaround other than committing this file into the repository and using "build with parameters", which isn't really a workaround.

          I guess another workaround would be to just change everywhere in the Jenkinsfile that references the parameter to the desired boolean value. It's not really testing what you plan to commit, but it simulates the desired behavior.

          dwatroustrinet Daniel Watrous added a comment - I also tried going in to the config.xml for that job and manually removing the parameters <hudson.model.BooleanParameterDefinition> <name>myParameter</name> <description>Set to true if you want to live</description> <defaultValue> true </defaultValue> </hudson.model.BooleanParameterDefinition> They were rewritten with the updated default value, but the build still ignores the default value and uses whatever the parameters were for that last build. I can't find a workaround other than committing this file into the repository and using "build with parameters", which isn't really a workaround. I guess another workaround would be to just change everywhere in the Jenkinsfile that references the parameter to the desired boolean value. It's not really testing what you plan to commit, but it simulates the desired behavior.
          kamilliano kamil wezka added a comment -

          I just wanted add my comment. Should the script be:

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

          because I think the `params.RUN_TESTS` is just a pointer to parameter reference that is always non null so if you don't use equality operators it is always true. Possibly this is not clear?

           

          kamilliano kamil wezka added a comment - I just wanted add my comment. Should the script be: script { if (params.RUN_TESTS == true ) { echo " true : $RUN_TESTS" } else echo " false : $RUN_TESTS" } because I think the `params.RUN_TESTS` is just a pointer to parameter reference that is always non null so if you don't use equality operators it is always true. Possibly this is not clear?  
          quhu Quirin Huber added a comment -

          Boolean parameter is not of type boolean but string. (You are comparing apples to pears)

          try: 

          script {
           if (params.RUN_TESTS.toBoolean() == true) {
           echo "true: $RUN_TESTS"
           }
           else echo "false: $RUN_TESTS"
           }
          
          quhu Quirin Huber added a comment - Boolean parameter is not of type boolean but string. (You are comparing apples to pears) try:  script { if (params.RUN_TESTS.toBoolean() == true ) { echo " true : $RUN_TESTS" } else echo " false : $RUN_TESTS" }

          People

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

            Dates

              Created:
              Updated: