Trigger previous stages in Jenkins Blue Ocean if user click on restart stage button

We use ephemeral build environment, which are Docker agent containers in Nomad that are destroyed after every Jenkins job run. Occasionally, developers attempt to restart a failed stage in Jenkins Blue Ocean, but this process fails automatically because previous stages are not triggered on the newly created Docker agent container. Is it possible to configure Jenkins to run previous stages or the entire pipeline from the beginning regardless of which stage the developer tries to restart?

Yes, it is possible to configure Jenkins to run previous stages or the entire pipeline from the beginning regardless of which stage the developer tries to restart. One way to do this is by adding a “rebuild” button to your pipeline’s build history in Blue Ocean. This button allows developers to easily rebuild the pipeline from any stage, including previous stages that were not triggered due to the use of ephemeral build environments.

To add the “rebuild” button, you can use the Rebuilder plugin for Jenkins. This plugin adds a “rebuild” action to your build history in Blue Ocean, allowing developers to restart a failed stage or rebuild the entire pipeline from any previous stage. To install the plugin, go to the Jenkins plugin manager and search for “Rebuilder.”

Once the plugin is installed, you can configure the “rebuild” action by adding it to your pipeline’s post-build actions in your pipeline script. Here is an example of how to add the “rebuild” action:

pipeline {
    agent {
        label 'docker'
    }
    stages {
        // your stages here
    }
    post {
        always {
            rebuild()
        }
    }
}

With the “rebuild” action configured, developers can now easily rebuild the pipeline from any stage, ensuring that all previous stages are triggered on the newly created Docker agent container.

Hi @ilyataskaev, quick question since this message is the only one about Jenkins+Nomad in the Community. Do you create custom agent containers based on the jenkins/inbound-agent container and then create Clouds in Jenkins based on those? Like have a jenkins/inbound-agent with docker installed to do docker builds, install python for python package builds, etc? Thanks!

Hello @pavfdev and welcome to this community :wave:

I know the question is not for me, but I’ve heard numerous times that the good practice was to start from the official inbound-agent, docker-agent, or ssh-agent images and to extend them to add your needed tools/packages.
I know some specific (i.e. python) “official” images exist, but they are not really maintained (even if published regularly).
The python one for example, has some parts of the inbound-agent, and some parts of the official python image, but misses essential parts of the two base images (like git for example).

Hi @poddingue and thanks for replying on this, I really appreciate it! This is the missing piece then. I tried the other jnlp-docker and python agent and that seems to work (just have to mount the var/run/docker.sock to the environment. I had inspected the layers in those images before and assumed they were unrelated but I now I see they do work together.

Do you know if it’s possible to make use of the agent stanza in the jenkinsfile to pass a custom job template or even a parameter like a container? It seems like it’s not from the GitHub issues but I’m wondering if you’ve seen otherwise.

1 Like