Complete the code to delete all files in the Jenkins workspace.
steps.sh 'rm -rf [1]/*'
The environment variable ${WORKSPACE} points to the current Jenkins job workspace directory. Using it ensures the cleanup targets the correct folder.
Complete the Jenkins pipeline step to clean the workspace before starting the build.
pipeline {
agent any
stages {
stage('Cleanup') {
steps {
[1]()
}
}
}
}
deleteDir() which deletes the current directory but may not clean all workspace files.The cleanWs() step is a Jenkins Pipeline utility that cleans the current workspace safely.
Fix the error in the shell command to clean the workspace safely.
sh 'rm -rf [1]'
Using ${WORKSPACE}/* deletes all files inside the workspace but keeps the workspace directory itself intact, preventing errors.
Fill both blanks to create a post-build step that cleans the workspace only if the build fails.
post {
failure {
steps {
[1]()
sh 'rm -rf [2]/*'
}
}
}deleteDir() which may delete the workspace folder itself.${WORKSPACE}.The cleanWs() step cleans the workspace safely. Using ${WORKSPACE} ensures the shell command targets the correct directory.
Fill all three blanks to define a pipeline that cleans workspace before and after the build.
pipeline {
agent any
stages {
stage('Cleanup') {
steps {
[1]()
}
}
stage('Build') {
steps {
echo 'Building...'
}
}
}
post {
always {
[2]()
sh 'rm -rf [3]/*'
}
}
}
Using cleanWs() in the cleanup stage and post steps ensures workspace is cleaned before and after the build. The ${WORKSPACE} variable targets the correct directory in the shell command.