如何在签出Jenkinsfile中的存储库之前清理管道 [英] How to cleanup pipeline before checkout of repository in Jenkinsfile
问题描述
我要执行clean before checkout
操作,该操作在Jenkins git插件文档中进行了描述:
I want to make a clean before checkout
operation which is described in Jenkins git plugin documentation:
在结帐前清洁每次结帐前都要清洁工作区,方法是 删除所有未跟踪的文件和目录,包括那些 在.gitignore中指定. ...
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:
options指令允许配置特定于管道的选项 从管道本身内部.管道提供了许多这些 选项,例如buildDiscarder,但它们也可能由 插件 ...
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...
但是,如何知道该插件提供哪些选项及其名称呢?没在文档中找到它,也可能我错了,应该将clean before checkout
放在Jenkinsfile的options
块中.
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.
请帮助.
推荐答案
正如注释中已经提到的,解决方法是使用skipDefaultCheckout()
(
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
跳过以下步骤从源代码管理中检出代码: 默认为agent指令.
Skip checking out code from source control by default in the agent directive.
要手动获取存储库,您可以使用checkout scm
(源)
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
}
}
}
}
这篇关于如何在签出Jenkinsfile中的存储库之前清理管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!