在开始新构建之前清理 Jenkins 所有阶段工作区

问题描述 投票:0回答:1

我有一个具有并行阶段的 Jenkins 管道,看起来像这样:

               / -- build -- test-xyz -- test-123--\
-- workspace--/                                     |--- Analyse -- upload results 
               \-- build -- test-abc -- test-456 --/

并行阶段在单独的节点上运行,并将消耗 w1、w1@1、w1@2、w1@3 等工作空间。我想在开始新构建之前删除所有这些。我已经尝试过使用 cleanWs() 但我们需要这些工作空间直到下一次构建。这就是为什么我正在寻找一些选项来在新构建之前清理工作区。

如有任何建议,我们将不胜感激?

期望有一个解决方案在开始新构建之前清理所有工作空间,例如 w1、w1@1、w1@2 等。

jenkins jenkins-plugins jenkins-groovy cicd
1个回答
0
投票

您可以在构建之前使用

cleanWs()
,插件文档有一个示例:

pipeline {
    agent any
    options {
        // This is required if you want to clean before build
        skipDefaultCheckout(true)
    }
    stages {
        stage('Build') {
            steps {
                // Clean before build
                cleanWs()
                // We need to explicitly checkout from SCM here
                checkout scm
                echo "Building ${env.JOB_NAME}..."
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.