Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop Jenkins checking out Git URL in a Pipeline stage

I have setup a Jenkins Declarative Pipeline job, and it pulls the Jenkinsfile from Git. I have a stage that is running on a another node (selected by a label), but it is trying to checkout the Jenkinsfile from Git too.

How can I stop this behavior? This particular slave is on the other side of a firewall and I can only reach it by SSH.

like image 284
David I. Avatar asked Sep 28 '17 18:09

David I.


People also ask

What is checkout in Jenkins pipeline?

Jenkins provides a very simple out of the box way of checking out code in pipeline. checkout scm . It will simply checkout code's version which triggered the run. However in case you want more control then you need to customise the checkout process.

What is checkout scm in Jenkins?

1. The checkout step will checkout code from source control; scm is a special variable which instructs the checkout step to clone the specific revision which triggered this Pipeline run.

How do I skip a Jenkins stage?

You can skip stages in declarative pipelines using when , so the following should work. stages { stage('Deploy') { when { equals expected: true, actual: Deploy } steps { // ... } } }


1 Answers

You can use the skipDefaultCheckout() in the options block. This will disable the checkout of the SCM on any node in any stage, so you will have to do a checkout scm step in the other stages manually.

pipeline {
    agent any
    options { skipDefaultCheckout() }
    stages{
        stage('first stage') {
            steps {
                checkout scm   
            }
        }
    }
}
like image 190
Rob Hales Avatar answered Oct 17 '22 04:10

Rob Hales