Jenkins Pipeline Wipe Out Workspace

前端 未结 13 1427
你的背包
你的背包 2020-12-04 08:59

We are running Jenkins 2.x and love the new Pipeline plugin. However, with so many branches in a repository, disk space fills up quickly.

Is there any plugin that

相关标签:
13条回答
  • 2020-12-04 09:40

    Using the 'WipeWorkspace' extension seems to work as well. It requires the longer form:

    checkout([
       $class: 'GitSCM',
       branches: scm.branches,
       extensions: scm.extensions + [[$class: 'WipeWorkspace']],
       userRemoteConfigs: scm.userRemoteConfigs
    ])
    

    More details here: https://support.cloudbees.com/hc/en-us/articles/226122247-How-to-Customize-Checkout-for-Pipeline-Multibranch-

    Available GitSCM extensions here: https://github.com/jenkinsci/git-plugin/tree/master/src/main/java/hudson/plugins/git/extensions/impl

    0 讨论(0)
  • 2020-12-04 09:40

    For Jenkins 2.190.1 this works for sure:

        post {
            always {
                cleanWs deleteDirs: true, notFailBuild: true
            }
        }
    
    0 讨论(0)
  • 2020-12-04 09:41

    Cleaning up : Since the post section of a Pipeline is guaranteed to run at the end of a Pipeline’s execution, we can add some notification or other steps to perform finalization, notification, or other end-of-Pipeline tasks.

    pipeline {
        agent any
        stages {
            stage('No-op') {
                steps {
                    sh 'ls'
                }
            }
        }
        post {
            cleanup {
                echo 'One way or another, I have finished'
                deleteDir() /* clean up our workspace */
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-04 09:49

    In fact the deleteDir function recursively deletes the current directory and its contents. Symbolic links and junctions will not be followed but will be removed.

    To delete a specific directory of a workspace wrap the deleteDir step in a dir step.

    dir('directoryToDelete') {
        deleteDir()
    }
    
    0 讨论(0)
  • 2020-12-04 09:52

    Currently both deletedir() and cleanWs() do not work properly when using Jenkins kubernetes plugin, the pod workspace is deleted but the master workspace persists

    it should not be a problem for persistant branches, when you have a step to clean the workspace prior to checkout scam. It will basically reuse the same workspace over and over again: but when using multibranch pipelines the master keeps the whole workspace and git directory

    I believe this should be an issue with Jenkins, any enlightenment here?

    0 讨论(0)
  • 2020-12-04 09:53

    Like @gotgenes pointed out with Jenkins Version. 2.74, the below works, not sure since when, maybe if some one can edit and add the version above

    cleanWs()
    

    With, Jenkins Version 2.16 and the Workspace Cleanup Plugin, that I have, I use

    step([$class: 'WsCleanup'])
    

    to delete the workspace.

    You can view it by going to

    JENKINS_URL/job/<any Pipeline project>/pipeline-syntax
    

    Then selecting "step: General Build Step" from Sample step and then selecting "Delete workspace when build is done" from Build step

    0 讨论(0)
提交回复
热议问题