Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declarative Jenkins Pielines to run a command before SCM checkout

Need to run a command before git checkout starts through pipeline code. It is similar to using Run buildstep before SCM runs. Thanks in advance

like image 645
arpitha bandri Avatar asked Sep 17 '25 10:09

arpitha bandri


1 Answers

You need to use the options at the beginning to prevent it doing the default checkout first and then trigger the checkout after your initial steps that you wish to do beforehand.

So in your pipeline script declare you agent/tools installations/environment vars then use

options {
    skipDefaultCheckout true
}

Then do your pre steps in a stage e.g.

stage('Preparation') {
     steps {
          //Insert steps here
     }
}

Your next stage should then do the checkout that you stopped earlier. This is really simple

stage('Checkout') {
    steps {
         checkout scm
    }
}

Then you can continue your normal steps. Took me a while to find this solution also. I use this to check out another repo first and read it's tag to generate combined version numbers.

like image 129
NinjaGnome Avatar answered Sep 19 '25 06:09

NinjaGnome