'Preventing default checkout in shared Jenkinsfile

I have a number of multi-branch pipeline jobs in Jenkins on Windows, each of which uses a standard procedural Jenkinsfile which contains various methods for running the build on our build farm, including methods for calculating a sensible place to checkout the source to.

The problem I'm having is that when pushing to a branch with a very long name the associated build fails because the path that Jenkins is trying to checkout the branch to is too long.

It seems the checkout that is causing the failure is the "default" checkout that Jenkins performs, and not the checkout that is performed by the Jenkinsfile for which appropriate paths have been calculated.

From some fairly extensive Googling it looks like I need to prevent this default checkout using skipDefaultCheckout() but it's not clear how it should be done in this situation.

Each project has a Jenkinsfile in its root directory which contains the following:

node {
    standardJenkinsfile.include()
}

The standardJenkinsfile is configured as a Global Pipeline Library. The include() method coordinates the build.

I have tried adding skipDefaultCheckout() to the project's Jenkinsfile before calling the standard Jenkinsfile, and I have also tried adding it to the start of the standardJenkinsfile.include() method, but the default checkout is still occurring.

Is there a way with this configuration to prevent the default checkout? Or at least specify the destination directory of the checkout?



Solution 1:[1]

You can use an option to do that in a DSL pipeline

pipeline {
agent any
options {
    skipDefaultCheckout()
  }
  stages {
    stage('Init') {
    }
  }
}

Here is how it is done in SAP S/4HANA Cloud SDK CICD Pipeline https://github.com/SAP/cloud-s4-sdk-pipeline/blob/master/s4sdk-pipeline.groovy#L11

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1