How to cleanup pipeline before checkout of repository in Jenkinsfile

末鹿安然 提交于 2020-12-12 11:39:48

问题


I want to make a clean before checkout operation which is described in Jenkins git plugin documentation:

Clean before checkout Clean the workspace before every checkout by deleting all untracked files and directories, including those which are specified in .gitignore. ...

But how can add this option to default checkout step which is doing as first step?

I feel that it should be an option extended by git plugin which can be included to options block of Jenkinsfile as described in docs:

The options directive allows configuring Pipeline-specific options from within the Pipeline itself. Pipeline provides a number of these options, such as buildDiscarder, but they may also be provided by plugins...

But how one should know which options and their names this plugin offer? Didn't find it in docs, also i may be wrong that clean before checkout should be placed in options block of Jenkinsfile.

Please help.


回答1:


As already mentioned in the comments the way to go is to use skipDefaultCheckout() (Source) in your pipeline-options to not checkout the repository if the pipeline starts.

skipDefaultCheckout

Skip checking out code from source control by default in the agent directive.

To get the repository manually you can use checkout scm (Source)

pipeline {
    agent any
    options {
        skipDefaultCheckout()
    }
    stages {
        stage('Example') {
            steps {
                // Cleanup before starting the stage
                // deleteDir() / cleanWs() or your own way of cleaning up

                // Checkout the repository
                checkout scm 

                // do whatever you like
            }
        }
    }
}


来源:https://stackoverflow.com/questions/60958037/how-to-cleanup-pipeline-before-checkout-of-repository-in-jenkinsfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!