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

The selected option from Active Choice Parameter groovy script is not used when building a job periodically (using cron)

    Details

    • Similar Issues:

      Description

      Steps to reproduce:

      Given: I install the Active Choice Parameter plugin
      When: I configure a job to have an Active Choice Parameter having a Groovy script
      And: I set an option as selected in the Groovy script, but not the first option
      And: I configure the job to build periodically (using cron)
      Then: The job should start with the selected option as for the parameter value

      Instead: The job starts with the first option from the groovy script and not with the selected one.

      eg.

      Having one Active Choice parameter, named "options" defined by the following Groovy script:

      return[
      'option1',
      'option2:selected',
      'option3'
      ]
      

      Then, if you build the project by using a system groovy script like this:

      import hudson.model.*
       
      // get ACP 'options'
      def resolver = build.buildVariableResolver
      def optionsACPValue = resolver.resolve("options").toString()
      
      // print 'options' ACP value
      
      println ("ACP value: '$\{optionsACPValue}'.")
      

      Output

      If you build manually you will get:

      *option2*
      

      and if you build periodically (using cron), the output will be:

      *option1*
      

        Attachments

          Activity

          Hide
          alin_brados Alin Brados added a comment - - edited

          If for ex, you have the following for the ACP:
          return[

          'option2:selected',
          'option1',
          'option3'
          ]

           

          Output:

          If you build manually you will get:

          option2

          and if you build periodically (using cron), the output will be:

          option2:selected

          Show
          alin_brados Alin Brados added a comment - - edited If for ex, you have the following for the ACP: return[ 'option2:selected', 'option1', 'option3' ]   Output: If you build manually you will get: option2 and if you build periodically (using cron), the output will be: option2:selected
          Hide
          ian_zelikman Ian Zelikman added a comment -

          I believe we are seeing a similar issue when the job is being called from an upstream job and a parameter is not. In that case similar to the example Alin Brados gave the value is set to `option: selected`

          Show
          ian_zelikman Ian Zelikman added a comment - I believe we are seeing a similar issue when the job is being called from an upstream job and a parameter is not. In that case similar to the example Alin Brados gave the value is set to `option: selected`
          Hide
          kinow Bruno P. Kinoshita added a comment -

          Nicely reported Alin Brados. I have an idea already of a possible way to fix it, but working on 1.5.4 now. Can't promise to include this issue right now as we've already triaged a few. But we can work on 1.5.5. in a couple of weeks perhaps. Pull requests welcome!

          Show
          kinow Bruno P. Kinoshita added a comment - Nicely reported Alin Brados . I have an idea already of a possible way to fix it, but working on 1.5.4 now. Can't promise to include this issue right now as we've already triaged a few. But we can work on 1.5.5. in a couple of weeks perhaps. Pull requests welcome!
          Hide
          sumit_bh Sumit Bhardwaj added a comment -

          Any update on this issue?

          Show
          sumit_bh Sumit Bhardwaj added a comment - Any update on this issue?
          Hide
          pchadim Pavel Chadima added a comment -

          I have the same problem and it is important issue for me since my configured pipelines are scheduled for automatically executed nightly builds which is now useless. The only solution now is to execute some nightly builds when I leave work in the evening. I would really apreciate fixing this! Thanks.

          Show
          pchadim Pavel Chadima added a comment - I have the same problem and it is important issue for me since my configured pipelines are scheduled for automatically executed nightly builds which is now useless. The only solution now is to execute some nightly builds when I leave work in the evening. I would really apreciate fixing this! Thanks.
          Hide
          mbush Marc Bush added a comment -

          I just ran into this issue as well. Only the first selection is passed forward from a scheduled build. Further more ":selected" is also passed to the next job.

          When running manually all selections are passed and ":selected" is not included

          Show
          mbush Marc Bush added a comment - I just ran into this issue as well. Only the first selection is passed forward from a scheduled build. Further more ":selected" is also passed to the next job. When running manually all selections are passed and ":selected" is not included
          Hide
          pchadim Pavel Chadima added a comment -

          For those who face the same problem, I applied a simple hack to solve this (moreover, it will work even when this bug is fixed). At the beginning of my automatic pipeline (executed by cron) I have this "if" for switching to default settings in the case, this bug occurs. Just do the same in your case .

           

          if (Wrappers.contains("Java:selected"))
          {
              ClearcaseBranch="development"
              Wrappers="Java,Csharp"
              TestGroups="Functional,Abort"
              VSversions="win_2017"
          }

           

          Show
          pchadim Pavel Chadima added a comment - For those who face the same problem, I applied a simple hack to solve this (moreover, it will work even when this bug is fixed). At the beginning of my automatic pipeline (executed by cron) I have this "if" for switching to default settings in the case, this bug occurs. Just do the same in your case .   if (Wrappers.contains("Java:selected")) {     ClearcaseBranch="development"     Wrappers="Java,Csharp"     TestGroups="Functional,Abort"     VSversions="win_2017" }  
          Hide
          macdrega Joerg Schwaerzler added a comment - - edited

          We're facing the same issue. To work around this one and to support running on new branches we currently are using the following workaround:

          @NonCPS
          boolean triggeredByTimer() {
              currentBuild.getRawBuild().getCauses()[0] instanceof hudson.triggers.TimerTrigger.TimerTriggerCause
          }
          
          def activeTests = []
          if (triggeredByTimer() || params.Tests == null || params.Tests == "${allTestNames[0]}:selected") {
              echo "Triggered by timer: ${triggeredByTimer()}"
              echo "params.Tests = ${params.Tests}"
              echo "As a workaround for running a new branch and for https://issues.jenkins-ci.org/browse/JENKINS-42568 this run will be called with default options:"
              activeTests = allTestNames
          } else {
              activeTests = createListOfActiveTests(params.Tests)
          }
          
          Show
          macdrega Joerg Schwaerzler added a comment - - edited We're facing the same issue. To work around this one and to support running on new branches we currently are using the following workaround: @NonCPS boolean triggeredByTimer() { currentBuild.getRawBuild().getCauses()[0] instanceof hudson.triggers.TimerTrigger.TimerTriggerCause } def activeTests = [] if (triggeredByTimer() || params.Tests == null || params.Tests == "${allTestNames[0]}:selected" ) { echo "Triggered by timer: ${triggeredByTimer()}" echo "params.Tests = ${params.Tests}" echo "As a workaround for running a new branch and for https: //issues.jenkins-ci.org/browse/JENKINS-42568 this run will be called with default options:" activeTests = allTestNames } else { activeTests = createListOfActiveTests(params.Tests) }

            People

            • Assignee:
              kinow Bruno P. Kinoshita
              Reporter:
              alin_brados Alin Brados
            • Votes:
              8 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

              • Created:
                Updated: