jenkins - 如何在 check out Jenkinsfile 中的存储库之前清理管道

标签 jenkins jenkins-pipeline jenkins-plugins jenkins-declarative-pipeline jenkins-git-plugin

我想做一个 clean before checkout 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. ...



但是如何将此选项添加到作为第一步的默认结帐步骤?

我觉得它应该是 git 插件扩展的一个选项,可以包含到 options Jenkinsfile 块,如 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...



但是如何知道该插件提供了哪些选项及其名称?没有在文档中找到它,我也可能错了 clean before checkout应该放在options Jenkinsfile 块。

请帮忙。

最佳答案

正如评论中已经提到的,要走的路是使用 skipDefaultCheckout() ( Source ) 在您的管道选项中,以便在管道启动时不 check out 存储库。

skipDefaultCheckout

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



要手动获取存储库,您可以使用 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
            }
        }
    }
}

关于jenkins - 如何在 check out Jenkinsfile 中的存储库之前清理管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60958037/

相关文章:

amazon-web-services - 使用 groovy 脚本更新 jenkins 文件中的 aws 凭证

jenkins - 在新的EC2 Jenkins从站上首次执行Docker不起作用

jenkins - 在文件夹内创建 Jenkins 凭据时无法选择凭据类型

jenkins 不断抛出错误消息 431 原因 : Request Header Fields Too Large

java - 如何运行 Jenkins 并查看可视化运行的测试

powershell - 将 Powershell 脚本的返回值分配给 Groovy 变量

jenkins-pipeline - 如何访问标签中轴的值?

jenkins - 如何获取触发我的多分支 Jenkins 构建的 Github PR 的标签列表

php - 使用自定义构建环境插件时对Dockerfile的权限被拒绝

java - 错误 - trustAnchors 参数必须非空