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

Problem with the parameter value rendering for cascading parameters in the Jenkins Active Choices Plugin

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • active-choices-plugin
    • Jenkins version: 2.440.1 LTS (JDK17)

      Active Choices plugin version: 2.8.1
      (confirmed presence in v2.8.0-v2.8.4, allegedly present in v2.7.x, allegedly not present in v2.6.x)

      Jenkins Active Choices Plugin Parameter Rendering Bug

      This is a formal report of the issue related to the cascading parameters bug.

      The bug is related to the problem with the parameter value rendering for cascading parameters in the Jenkins Active Choices Plugin, primarily with the ordering of the dependent parameters.

      This issue has been reported already on multiple occasions:

      The bug caused cascading parameters (dynamic parameters + dynamic reference parameters) not to render correctly - the parameter values not being updated during the build UI interaction due to the lack of proper change propagation logic in the plugin.

      The Problem

      Our suspicion is that the root cause of the problem is most likely in one of the following:

      • UnoChoice frontend code
        • CascadeParameter.update() / DynamicReferenceParameter.update() methods
          • The methods returning prematurely due to incorrect use of asynchronous calls (e.g. Promise objects)
        • proxy.doUpdate() method
          • Potentially similar issues as stated above
      • Plugin Java code
        • AbstractCascadableParameter.update() method

      What is important to note is that the key problem is the clash between the parameter rendering timing which results in the wrong order of parameter rendering and the lack of proper change propagation logic in the plugin.

      The Solution (Workaround)

      We created a dedicated project for applying a fix / patch as a workaround for this project.

      More info is available here (on our GitHub).

      Pre-built patched bundles of the plugin (containing the workaround) are available here (on our GitHub) while we all wait for the maintainers to address and fix the issue.
      But please, make sure to read the associated documentation for a better understanding of what this workaround does, how it works, and what are its limitations. Also, preferably, for security reasons, you should build the patched plugin bundle yourself.

      We will also submit a proper PR which addresses this issue and attempts to fix it, but due to the nature of our current fix (a lot of code logic being appended to an existing JavaScript file), we are not sure what will the maintainers' reception be.

          [JENKINS-73935] Problem with the parameter value rendering for cascading parameters in the Jenkins Active Choices Plugin

          Lou Fiorino added a comment -

          the problems persist in 2.8.5

          Lou Fiorino added a comment - the problems persist in 2.8.5

          Also confirm this is still present in 2.8.5.

          Federico Alaimo added a comment - Also confirm this is still present in 2.8.5.

          Thank you both for confirming the problem in 2.8.5. This issue has great description, links to previous issues, and a tentative fix (which cannot be merged as-is, but is great to help debugging the problem). I have to have a look at the issues in TAP Plug-in, and will come back to this one (not going to work on other issues for 2.8.6, so that release will be just for another try at fixing this issue).

          I note too the comment in the OP "The methods returning prematurely due to incorrect use of asynchronous calls (e.g. Promise objects)"; the promises were introduced in a previous release to make the code asynchronous – that caused the whole lot of issues related here. I tried reverting that, so there is a possible (not sure how likely) fix that involves simply finding out if I reverted the code correctly, or if I missed a part which is still causing this issue.

          If anyone has some config.xml, or detailed configurations that could be used to reproduce it, that'd be great. I added a e2e test for another issue that reported a possible scenario to reproduce this issue, but maybe a) the test is not good enough or b) there are other scenarios where the issue happens. In case of b), I'd like to add more tests to improve quality here.

          Cheers

          Bruno P. Kinoshita added a comment - Thank you both for confirming the problem in 2.8.5. This issue has great description, links to previous issues, and a tentative fix (which cannot be merged as-is, but is great to help debugging the problem). I have to have a look at the issues in TAP Plug-in, and will come back to this one (not going to work on other issues for 2.8.6, so that release will be just for another try at fixing this issue). I note too the comment in the OP "The methods returning prematurely due to incorrect use of asynchronous calls (e.g. Promise objects)"; the promises were introduced in a previous release to make the code asynchronous – that caused the whole lot of issues related here. I tried reverting that, so there is a possible (not sure how likely) fix that involves simply finding out if I reverted the code correctly, or if I missed a part which is still causing this issue. If anyone has some config.xml, or detailed configurations that could be used to reproduce it, that'd be great. I added a e2e test for another issue that reported a possible scenario to reproduce this issue, but maybe a) the test is not good enough or b) there are other scenarios where the issue happens. In case of b), I'd like to add more tests to improve quality here. Cheers

          Lou Fiorino added a comment -

          I would normally be happy to provide sample pipelines, however unfortunately most if not all of our utilization of this plugin involve pipeline sunder SCM that also invoke INTERNAL web services so they would not provide a practical example that would be useful.  When trying to MODIFY one to just return hard coded strings in lieu of the web service alter the timing of the asynchronous responses and refreshes and do not consistently reflect the issues

          Lou Fiorino added a comment - I would normally be happy to provide sample pipelines, however unfortunately most if not all of our utilization of this plugin involve pipeline sunder SCM that also invoke INTERNAL web services so they would not provide a practical example that would be useful.  When trying to MODIFY one to just return hard coded strings in lieu of the web service alter the timing of the asynchronous responses and refreshes and do not consistently reflect the issues

          Eric added a comment -

          I am also experiencing this issue and was hoping the closure of JENKINS-71909 would fix it. Unfortunately it did not. I built a barebones Jenkinsfile that consistently demonstrates the issue for me.

          properties([
              parameters([
                  choice(name: 'one', choices:['1','2','3'], description: 'One'),
                  [$class: 'CascadeChoiceParameter',
                      choiceType: 'PT_SINGLE_SELECT',
                      description: 'Two',
                      name: 'two',
                      referencedParameters: 'one',
                      script: [$class: 'GroovyScript',
                          script: [
                              classpath: [],
                              sandbox: true,
                              script: """ 
                                  if (one.equals("1"))
                                      return ["1a:selected", "1b", "1c"]
                                  else if (one.equals("2"))
                                      return ["2a:selected", "2b", "2c"]
                                  else if (one.equals("3"))
                                      return ["3a:selected", "3b", "3c"]
                                  assert false
                              """
                          ]
                      ]
                  ],
                  [$class: 'CascadeChoiceParameter',
                      choiceType: 'PT_SINGLE_SELECT',
                      description: 'the combination of one and two.',
                      name: 'three',
                      referencedParameters: 'one,two',
                      script: [$class: 'GroovyScript',
                          script: [
                              classpath: [],
                              sandbox: true,
                              script: 'return ["${one}/${two}:selected"]'
                          ]
                      ]
                  ]
              ])
          ])
          
          pipeline{
            agent any  stages{
              stage('Echo'){
                steps{
                  script{
                      sh 'echo ${one} ${two} ${three}'
                  }
                }
              }
            }
          }

          I experience two issues with this pipeline.

          1. When initially loading the parameters page option "three" fails to load and just shows the spinning circle.
          2. When changing option "one" the value of option "three" does not accurately reflect the values visible in options "one" and "two".

          Eric added a comment - I am also experiencing this issue and was hoping the closure of JENKINS-71909 would fix it. Unfortunately it did not. I built a barebones Jenkinsfile that consistently demonstrates the issue for me. properties([     parameters([         choice(name: 'one' , choices:[ '1' , '2' , '3' ], description: 'One' ),         [$class: 'CascadeChoiceParameter' ,             choiceType: 'PT_SINGLE_SELECT' ,             description: 'Two' ,             name: 'two' ,             referencedParameters: 'one' ,             script: [$class: 'GroovyScript' ,                 script: [                     classpath: [],                     sandbox: true ,                     script: """                          if (one.equals( "1" ))                             return [ "1a:selected" , "1b" , "1c" ]                         else if (one.equals( "2" ))                             return [ "2a:selected" , "2b" , "2c" ]                         else if (one.equals( "3" ))                             return [ "3a:selected" , "3b" , "3c" ]                         assert false                     """                 ]             ]         ],         [$class: 'CascadeChoiceParameter' ,             choiceType: 'PT_SINGLE_SELECT' ,             description: 'the combination of one and two.' ,             name: 'three' ,             referencedParameters: 'one,two' ,             script: [$class: 'GroovyScript' ,                 script: [                     classpath: [],                     sandbox: true ,                     script: ' return [ "${one}/${two}:selected" ]'                 ]             ]         ]     ]) ]) pipeline{   agent any  stages{     stage( 'Echo' ){       steps{         script{             sh 'echo ${one} ${two} ${three}'         }       }     }   } } I experience two issues with this pipeline. When initially loading the parameters page option "three" fails to load and just shows the spinning circle. When changing option "one" the value of option "three" does not accurately reflect the values visible in options "one" and "two".

          Lou Fiorino added a comment -

          the problem persists in 2.8.6

          Lou Fiorino added a comment - the problem persists in 2.8.6

          Mars Wong added a comment -

          Just to mark it up a bit, it seems that the issue still exists in version 2.8.6

          Mars Wong added a comment - Just to mark it up a bit, it seems that the issue still exists in version 2.8.6

          Thanks for confirming it is still happening

           

          Bruno P. Kinoshita added a comment - Thanks for confirming it is still happening  

            kinow Bruno P. Kinoshita
            hossted Hossted
            Votes:
            9 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated: