0

In a declarative Jenkins pipeline, I need to introduce a stage X as another downstream for multiple upstream stages (B1, B2) which already have their corresponding downstream stages (C1,C2).

The visual representation of existing pipeline is as follows. enter image description here

This is described using below declarative pipeline syntax.

pipeline {
    agent any
    stages {
        stage('A'){
        ...
        }
        stage('BC'){
            paralle {
                stage('1'){
                    stages {
                        stage('B1'){
                        ...
                        }
                        stage('C1'){
                        ...
                        }
                    }
                }
                stage('2'){
                    stages {
                        stage('B2'){
                        ...
                        }
                        stage('C2'){
                        ...
                        }
                    }   
                }
            }
        }
        stage('D') {
        ...         
        }
    }
}

I need to perform certain steps when stages B1 and B2 are complete. This I am planning to achieve by introducing a stage X as illustrated below.

enter image description here

How to add stage X in existing pipeline? Is there any other mechanism to execute certain steps after B1 and B2 both are complete and without waiting for stages C1,C2 and D?

Nazil Khan
  • 135
  • 2
  • 9
  • 1
    One possible way could be to introduce the stage X outside the `parallel` block after B1 and B2, i.e., at the same level as A and D. Then after X, start another `parallel` block consisting of C1, C2, etc. Now, if you want to end the pipeline execution after X, bypassing C1 and C2 as in your diagram, then introduce appropriate `when` conditional before them. – Dibakar Aditya Oct 26 '19 at 20:11
  • A -> B1,B2 - > X -> C1,C2 -> D. Can be a workaround but it will not let C continue if any of the B's are taking time to execute. Rather than introducing X as a stage, can it be achieved with some other pipeline construct? – Nazil Khan Oct 27 '19 at 04:52
  • I can’t think of anything except that you can write a function with the steps that you want inside X, and then call that function twice - once each within/after B1 and B2. Meanwhile keep this question open for the more knowledgeable members to respond. – Dibakar Aditya Oct 27 '19 at 08:34

0 Answers0