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

Add ability to always run particular stages when restarting

    • Declarative backlog

      I would like to have the ability when restarting a pipeline to always execute a block before the restarted stages begin. The reasoning for this is that I may have some job setup that must always occur when restarting a particular stage.

      For example, consider the following:

      Setup -> Stage 1 -> Stage 2 -> Stage 3

      Let's say I would like to restart from Stage 2 but it needs the setup stage to function properly. Picking Stage 2 as the restart point would then trigger Setup, Stage 2, and then Stage 3.

      We already have a post block, so perhaps it would make sense to have a pre block that can be configured to run when a pipeline is restarted? Or perhaps you can just mark a stage to run even when restarted?

      I realize that it's probably a best practice to have each stage be modular and self-contained, but we have some data we must lay down on the  node that is unique to each run and later stages depend on it. Currently, it's just the first stage in our pipeline and it does not run if we restart the pipeline at a later stage.

      We had a small discussion regarding this in JENKINS-51932.

          [JENKINS-53167] Add ability to always run particular stages when restarting

          Andrew Bayer added a comment -

          This is an interesting possibility - no guarantees, but this does feel worth considering.

          Andrew Bayer added a comment - This is an interesting possibility - no guarantees, but this does feel worth considering.

          I would really like this feature too.

          I have 2 use cases for this feature, the first is I would like to send a notification when a pipeline starts regardless of how it was triggered, there is no real nice way to do this currently for stage restarts.

          The second use case is I want to load some config/metadata that was generated from a skipped stage allowing me to restart from any stage, however because I can't know which will be the restarted stage I need to try load it in every stage and this just makes my Jenkinsfile look unnecessarily cluttered.

          In both cases having a pipeline pre stage would simplify my Jenkinsfile and declutter it making it easier to read and maintain

          Jonathan Kuleff added a comment - I would really like this feature too. I have 2 use cases for this feature, the first is I would like to send a notification when a pipeline starts regardless of how it was triggered, there is no real nice way to do this currently for stage restarts. The second use case is I want to load some config/metadata that was generated from a skipped stage allowing me to restart from any stage, however because I can't know which will be the restarted stage I need to try load it in every stage and this just makes my Jenkinsfile look unnecessarily cluttered. In both cases having a pipeline pre stage would simplify my Jenkinsfile and declutter it making it easier to read and maintain

          This is one of the cool features we would like to have with jenkins. Many of our use cases are built around this and it really makes life much easier to restart the stage in parallel stages. 

          Harshavardhan Musanalli added a comment - This is one of the cool features we would like to have with jenkins. Many of our use cases are built around this and it really makes life much easier to restart the stage in parallel stages. 

          Garbageyard added a comment -

          I am also looking for this functionality for my use case. If my scm checkout and build phases run fine but test case execution fails, then in such case, i would like to run the checkout (which will now have fix for test case issue) and test case again but skip the build phase. Actually, the ability to run a particular phase as an optional feature will be the most ideal situation for me.

          Garbageyard added a comment - I am also looking for this functionality for my use case. If my scm checkout and build phases run fine but test case execution fails, then in such case, i would like to run the checkout (which will now have fix for test case issue) and test case again but skip the build phase. Actually, the ability to run a particular phase as an  optional  feature will be the most ideal situation for me.

          Weynham Zheng added a comment -

          Is there any workaround to accomplish this requirement?

          Weynham Zheng added a comment - Is there any workaround to accomplish this requirement?

          toh rong quan added a comment -

          Yes, it is very needed to preserve some variables/config defined in earlier stage to be used in later stage. 

          toh rong quan added a comment - Yes, it is very needed to preserve some variables/config defined in earlier stage to be used in later stage. 

          Ruchita Sheri added a comment -

          We have a "Deploy to QA" stage in the pipeline and after deploying to a particular environment, I want to re-deploy the same successful build to another environment. The restart option on the blue ocean UI triggers the entire pipeline and the build happens to fail. Is it possible to achieve this functionality with existing Jenkins version?

          Ruchita Sheri added a comment - We have a "Deploy to QA" stage in the pipeline and after deploying to a particular environment, I want to re-deploy the same successful build to another environment. The restart option on the blue ocean UI triggers the entire pipeline and the build happens to fail. Is it possible to achieve this functionality with existing Jenkins version?

          Agreed. I need to run my "initialize" stage before skipping the next n stages and starting at stage n + 1.

          Josh McCullough added a comment - Agreed. I need to run my "initialize" stage before skipping the next  n stages and starting at stage  n + 1 .

            Unassigned Unassigned
            bdevcich Blake Devcich
            Votes:
            19 Vote for this issue
            Watchers:
            22 Start watching this issue

              Created:
              Updated: