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

Boolean input parameter ignores default value of false

      If your pipeline groovy script has an input step which is a BooleanParameterDefinition, the default value is always true. Setting the default value to false has no effect.

      Example generated by snippet generator:

      input id: 'Test', message: 'testing123', ok: 'Deploy', parameters: [[$class: 'BooleanParameterDefinition', defaultValue: false, description: '', name: 'test']]
      

          [JENKINS-36543] Boolean input parameter ignores default value of false

          I see this problem also with Choice input parameters, where the first in the list (expressed using e.g. choices: "yes\nno\n") is always selected.
          The incorrect defaults for choice show also in:
          Paused for input e.g. http://localhost:8080/job/pipeline-name/job/branchname/59/input/
          Blue Ocean e.g. http://localhost:8080/blue/organizations/jenkins/pipeline-name/detail/branchname59/pipeline/

          Jeremy Carroll added a comment - I see this problem also with Choice input parameters, where the first in the list (expressed using e.g. choices: "yes\nno\n" ) is always selected. The incorrect defaults for choice show also in: Paused for input e.g. http://localhost:8080/job/pipeline-name/job/branchname/59/input/ Blue Ocean e.g. http://localhost:8080/blue/organizations/jenkins/pipeline-name/detail/branchname59/pipeline/

          Michael Doubez added a comment - - edited

          Same issue in Jenkins 1.651.3.

          The API request seems good:

          {  "id":"Afdd284c9c42d46edfd421228b55be59",
             "proceedText":"Proceed",
             "message":"Boolean input test",
              "inputs": [{"type":"BooleanParameterDefinition","name":"foo","definition":{"defaultVal":false}}],
              ....
          

          When looking at the HTML source, I see correct data:

          <div class="input cbwf-info-action-popover run-input-required">
              <div class="remove"><span class="glyphicon glyphicon-remove remove"></span></div>
              <div class="caption">Boolean input test</div>
              <div class="form">
                  <div class="inputs">
                          <div class="checkbox">
                              <label>
                                  <input name="foo" checked="false" type="checkbox">foo
                              </label>
                              
                          </div>
                  </div>
                  <div class="buttons">
                      <button type="submit" class="btn btn-primary btn-sm proceed-button">Proceed</button>
                      <button type="submit" class="btn btn-default btn-sm abort-button">Abort</button>
                  </div>
              </div>
          
          </div>
          

          But the display is a checked box.

          The issue should be somewhere in the javascript of pipeline-stage-view-plugin.

          Michael Doubez added a comment - - edited Same issue in Jenkins 1.651.3. The API request seems good: { "id" : "Afdd284c9c42d46edfd421228b55be59" , "proceedText" : "Proceed" , "message" : " Boolean input test" , "inputs" : [{ "type" : "BooleanParameterDefinition" , "name" : "foo" , "definition" :{ "defaultVal" : false }}], .... When looking at the HTML source, I see correct data: <div class= "input cbwf-info-action-popover run-input-required" > <div class= "remove" ><span class= "glyphicon glyphicon-remove remove" ></span></div> <div class= "caption" > Boolean input test</div> <div class= "form" > <div class= "inputs" > <div class= "checkbox" > <label> <input name= "foo" checked= " false " type= "checkbox" >foo </label> </div> </div> <div class= "buttons" > <button type= "submit" class= "btn btn-primary btn-sm proceed-button" >Proceed</button> <button type= "submit" class= "btn btn- default btn-sm abort-button" >Abort</button> </div> </div> </div> But the display is a checked box. The issue should be somewhere in the javascript of pipeline-stage-view-plugin.

          Michael Doubez added a comment - - edited

          In fact, it shouldn't be checked=true/false but checked or empty string.

          https://www.w3.org/TR/2012/WD-html-markup-20121025/input.checkbox.html

          Code to change in https://github.com/jenkinsci/pipeline-stage-view-plugin/blob/ef8a7c7bfe516679ac0f29752287b2073954a230/ui/src/main/js/view/templates/run-input-required.hbs#L10

          <input name="{{name}}" type="checkbox" {{#definition.defaultVal}}checked{{/definition.defaultVal}} />{{name}}
          

          Michael Doubez added a comment - - edited In fact, it shouldn't be checked=true/false but checked or empty string. https://www.w3.org/TR/2012/WD-html-markup-20121025/input.checkbox.html Code to change in https://github.com/jenkinsci/pipeline-stage-view-plugin/blob/ef8a7c7bfe516679ac0f29752287b2073954a230/ui/src/main/js/view/templates/run-input-required.hbs#L10 <input name= "{{name}}" type= "checkbox" {{#definition.defaultVal}}checked{{/definition.defaultVal}} />{{name}}

          Lucas Cimon added a comment -

          Lucas Cimon added a comment - The pull request to fix this is here: https://github.com/jenkinsci/pipeline-stage-view-plugin/pull/37

          Code changed in jenkins
          User: Sam Van Oort
          Path:
          pom.xml
          ui/src/main/js/view/templates/run-input-required.hbs
          ui/src/test/js/view/run-input-required-spec.js
          ui/src/test/resources/view/run_input_required/input-model-01.json
          http://jenkins-ci.org/commit/pipeline-stage-view-plugin/8f7aece7596cdea8fec6a1d2b8d1674189328621
          Log:
          Merge pull request #37 from jbq/fix_checkbox_default_value

          JENKINS-36543 Honor defaultValue=false in BooleanParameterDefinition

          Compare: https://github.com/jenkinsci/pipeline-stage-view-plugin/compare/29b14fc6c51c...8f7aece7596c

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Sam Van Oort Path: pom.xml ui/src/main/js/view/templates/run-input-required.hbs ui/src/test/js/view/run-input-required-spec.js ui/src/test/resources/view/run_input_required/input-model-01.json http://jenkins-ci.org/commit/pipeline-stage-view-plugin/8f7aece7596cdea8fec6a1d2b8d1674189328621 Log: Merge pull request #37 from jbq/fix_checkbox_default_value JENKINS-36543 Honor defaultValue=false in BooleanParameterDefinition Compare: https://github.com/jenkinsci/pipeline-stage-view-plugin/compare/29b14fc6c51c...8f7aece7596c

          Sam Van Oort added a comment -

          Merged in now, pending release once I resolve a side effect from updating the plugin parent pom. 

          Sam Van Oort added a comment - Merged in now, pending release once I resolve a side effect from updating the plugin parent pom. 

          Sam Van Oort added a comment -

          Released with pipeline stage view plugin 2.8

          Sam Van Oort added a comment - Released with pipeline stage view plugin 2.8

          Brandon Chew added a comment -

          I've recently created a pipeline job using a Boolean Parameter and have noticed that this issue is still happening.  I'm using Pipeline Stage View plugin 2.9.  Did this get reverted somehow in 2.9?

          Brandon Chew added a comment - I've recently created a pipeline job using a Boolean Parameter and have noticed that this issue is still happening.  I'm using Pipeline Stage View plugin 2.9.  Did this get reverted somehow in 2.9?

          Brandon Chew added a comment -

          I've recently created a pipeline job using a Boolean Parameter and have noticed that this issue is still happening.  I'm using Pipeline Stage View plugin 2.9.  Did this get reverted somehow in 2.9?

          Brandon Chew added a comment - I've recently created a pipeline job using a Boolean Parameter and have noticed that this issue is still happening.  I'm using Pipeline Stage View plugin 2.9.  Did this get reverted somehow in 2.9?

          Sam Van Oort added a comment -

          bchew1288 I'm quite confident we didn't revert this – are you absolutely sure this is happening with 2.9 or 2.10? Can you provide a case to reproduce?

          Sam Van Oort added a comment - bchew1288 I'm quite confident we didn't revert this – are you absolutely sure this is happening with 2.9 or 2.10? Can you provide a case to reproduce?

            jbq jbq
            nkonstantakos Niko Konstantakos
            Votes:
            6 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated: