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

Directive Generator: `when` is missing `isRestartedRun()`

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • Jenkins:
      - Core 2.127
      - Experimental UC plugins
      - Declarative at 1.3.0-SNAPSHOT, which was master at commit eeb92e42

      Summary
      When using the Directive Generator, the generator for when is missing isRestartedRun().

      Steps to recreate
      1. Go to the Declarative Directive Generator via http://1.2.3.4:8080/job/your-pipeline-job/directive-generator/

      2. Pick the Sample Directive: when

      3. Look in the dropdown for When Condition. I was expecting to see `isRestartedRun`, but it's not there.

          [JENKINS-51932] Directive Generator: `when` is missing `isRestartedRun()`

          Karl Shultz created issue -
          Karl Shultz made changes -
          Attachment New: image-2018-06-13-14-59-55-242.png [ 42860 ]
          Description Original: *Summary*
          When using the Directive Generator, building a {{when}} / {{allOf}} directive with no conditions attached produces a NPE. This was another accidental find.

          *Steps to recreate*
          1. Go to the Declarative Directive Generator via {{http://1.2.3.4:8080/job/your-pipeline-job/directive-generator/}}

          2. Set it up as follows:
          * Sample Directive: {{when}}
          * whenCondition: {{allOf}}
          * Execute the stage if all nested conditions are true: no selections made

          3. And press the Generate Declarative Directive button, you'll get a NPE in your sample:
          {code:none}
          when {
            // ERROR TRANSLATING CONDITIONAL: java.lang.NullPointerException
          }
          {code}

          Accidental find.

           !image-2018-06-13-14-36-02-967.png|thumbnail!
          New: *Summary*
          When using the Directive Generator, the generator for {{when}} is missing {{isRestartedRun()}}.

          *Steps to recreate*
          1. Go to the Declarative Directive Generator via {{http://1.2.3.4:8080/job/your-pipeline-job/directive-generator/}}

          2. Pick the Sample Directive: {{when}}

          3. Look in the dropdown for When Condition. I was expecting to see `isRestartedRun`, but it's not there.

           !image-2018-06-13-14-59-55-242.png|thumbnail!
          Andrew Bayer made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Andrew Bayer made changes -
          Status Original: In Progress [ 3 ] New: In Review [ 10005 ]

          Andrew Bayer added a comment -

          Andrew Bayer added a comment - PR up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/279
          Andrew Bayer made changes -
          Remote Link New: This issue links to "PR #279 (Web Link)" [ 21272 ]

          Blake Devcich added a comment - - edited

          Is there documentation how this this isRestartedRun is used? If I put this in the when block of stage 1 and restart at stage 3 will it skip the stage 1 block or will it actually do stage 1 first, and then stage 3 and so on?

          I ask because I'm looking for a way to always run an earlier stage (to do some setup) no matter what stage is selected as the restart point.

          https://jenkins.io/doc/book/pipeline/syntax/#when makes no mention of this feature.

          Blake Devcich added a comment - - edited Is there documentation how this this isRestartedRun is used? If I put this in the when block of stage 1 and restart at stage 3 will it skip the stage 1 block or will it actually do stage 1 first, and then stage 3 and so on? I ask because I'm looking for a way to always run an earlier stage (to do some setup) no matter what stage is selected as the restart point. https://jenkins.io/doc/book/pipeline/syntax/#when makes no mention of this feature.

          Andrew Bayer added a comment -

          It allows you to only fire a stage if it's part of a restarted run (or, of course, with not, you can have it do the reverse). But this still only applies for stages from the restart point onward - if you restart at stage 3, stages 1 and 2 will always be skipped regardless.

          Andrew Bayer added a comment - It allows you to only fire a stage if it's part of a restarted run (or, of course, with not , you can have it do the reverse). But this still only applies for stages from the restart point onward - if you restart at stage 3, stages 1 and 2 will always be skipped regardless.

          Blake Devcich added a comment -

          Thanks Andrew! So just to confirm there's no way to always run a setup stage when a pipeline is restarted?

          The only thing I can think of right now is to have a function that is called in the beginning of every stage that is executed only on a restart.

          Blake Devcich added a comment - Thanks Andrew! So just to confirm there's no way to always run a setup stage when a pipeline is restarted? The only thing I can think of right now is to have a function that is called in the beginning of every stage that is executed only on a restart.

          Andrew Bayer added a comment -

          bdevcich - correct. It's an interesting idea, though - probably would be worth opening a JIRA for that as a new feature.

          Andrew Bayer added a comment - bdevcich - correct. It's an interesting idea, though - probably would be worth opening a JIRA for that as a new feature.

            abayer Andrew Bayer
            kshultz Karl Shultz
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: