0

How can we run two stages in parallel in Jenkins2.0 Pipeline project. For ex: in the following code i want to run the two stages to run in parallel i.e. "Build_First_Repo" and "Build_Second_Repo" should run in parallel.

stage "Build_First_Repo"
    node { sh '''echo 'Build first repo'
                 source ~/.bashrc'''
                 export path_to_perl_library="/path/to/perl/lib/perl5/5.8.8"
                 perl -I <include_files> build_first_view.pl --inputfile ${input_params}

        }


 stage "Build_Second_Repo"
    node { sh '''echo 'Build second repo'
                 source ~/.bashrc'''
                 export path_to_perl_library="/path/to/perl/lib/perl5/5.8.8"
                 perl -I <include_files> build_second_view.pl --inputfile ${input_params}

        }

I tried to use the "parallel" keyword but it didnt work.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Yash
  • 2,944
  • 7
  • 25
  • 43

1 Answers1

0

In declarative pipeline you cannot run stages within a parallel step because steps are part of the stage directive. The declarative flow is like stages -> stage -> steps -> the actual step that you perform.

But, you can achieve it in scripted pipeline. A sample is as follows:

node(){
    parallel first:{
    stage('stage1'){
        echo 'helloworld'
    }
    },
    second:{
    stage('stage2'){
        echo 'helloworld2'
    }
    }
}
dcrosta
  • 26,009
  • 8
  • 71
  • 83
Karthick
  • 319
  • 1
  • 3