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

Active Choices Reactive Reference Parameter triggering the groovy script twice

      I am trying to fetch a list of branches from git in the active choice reactive reference parameter.I am using the run groovy script option.

      But the script is ran twice when I check the tomcat logs.

      Because of which the drop down is rendered twice.

      Please find the below script

      def html=
       '''
       <div style="padding-top:-2em;margin-left:1em;">
       <select id="module" style="height:2.2em;width:10.8em" name="value">
       <option value="">Select...</option>
       '''
       def cmd = ["/bin/bash", "-c","sudo sh /home/centos/JenkinScripts/dynamicChoices/getBranchesFromGit.sh https://KGJenkins@bitbucket.org/vtakru/escloudadmin.git"]
       def sout = new StringBuffer()
       def serr = new StringBuffer()
       // Run the command
       println "running "+cmd
       def proc = cmd.execute()
       proc.consumeProcessOutput ( sout, serr )
       proc.waitFor() 
       def options=""
       sout.tokenize().each{ branch->
       if(branch.contains("refs/heads/")){
       branch=branch.minus("refs/heads/")
       println "Branch "+branch
       options+="<option value=$branch>$branch</option>"
       }
       }
       html+=options
       return html

       

      Please help me with this issue

       

          [JENKINS-49894] Active Choices Reactive Reference Parameter triggering the groovy script twice

          What version of AC are you working with. Can you please, report if this issue is present in the most recent AC plugin v2.1. Thank you.

          Ioannis Moutsatsos added a comment - What version of AC are you working with. Can you please, report if this issue is present in the most recent AC plugin v2.1. Thank you.

          Adam vonNieda added a comment -

           

             Hello, I've got the same issue, using Active Choices 2.1 (Jenkins LTS 2.150.1)

             Here's the code I'm executing. 

          def sout = new StringBuilder(), serr = new StringBuilder()
          def proc = ["sudo", "-u", "oragen", "/home/oragen/automation/scripts/git/pull.sh"].execute()
          proc.consumeProcessOutput(sout, serr)
          proc.waitForOrKill(5000)
          return "<p><b>Cloning the Git repository to local</b><p>" + sout + "<br>" + serr.text()

           

             If there's any sort of workaround I'd really appreciate it   Let me know if there's anything additional I can provide. 

             Thanks,

                   -Adam  

          Adam vonNieda added a comment -      Hello, I've got the same issue, using Active Choices 2.1 (Jenkins LTS 2.150.1)    Here's the code I'm executing.  def sout = new StringBuilder(), serr = new StringBuilder() def proc = [ "sudo" , "-u" , "oragen" , "/home/oragen/automation/scripts/git/pull.sh" ].execute() proc.consumeProcessOutput(sout, serr) proc.waitForOrKill(5000) return "<p><b>Cloning the Git repository to local</b><p>" + sout + "<br>" + serr.text()      If there's any sort of workaround I'd really appreciate it   Let me know if there's anything additional I can provide.     Thanks,          -Adam  

          Have just spent some minutes debugging it, and I believe I now understand what's causing the issue. Can't fix it right now due to limited bandwidth to develop, but the below is a short explanation of the problem (and also a note to myself in the future, when working on this issue again).

          I only reproduced it on the first time the page is loaded. Debugging, it is possible to see the first call comes from Jelly tags being evaluated. And the second call comes from JavaScript code.

          The issue appears to be that when we put the elements on the UI, we also intentionally call the update method on the server side, to get the right values. Then once everything is loaded, there is a JS call to refresh the elements' values.

          The ideal approach would be to have Jelly creating the elements, then using JS to start the execution. But that's not easy to implement without breaking other things.

          Bruno P. Kinoshita added a comment - Have just spent some minutes debugging it, and I believe I now understand what's causing the issue. Can't fix it right now due to limited bandwidth to develop, but the below is a short explanation of the problem (and also a note to myself in the future, when working on this issue again). I only reproduced it on the first time the page is loaded. Debugging, it is possible to see the first call comes from Jelly tags being evaluated. And the second call comes from JavaScript code. The issue appears to be that when we put the elements on the UI, we also intentionally call the update method on the server side, to get the right values. Then once everything is loaded, there is a JS call to refresh the elements' values. The ideal approach would be to have Jelly creating the elements, then using JS to start the execution. But that's not easy to implement without breaking other things.

          Adam vonNieda added a comment -

          Thanks for the update Bruno, I'm looking into a different way of doing what I need to in the meantime. 

          Adam vonNieda added a comment - Thanks for the update Bruno, I'm looking into a different way of doing what I need to in the meantime. 

            kinow Bruno P. Kinoshita
            akash0092 Akash Muduli
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: