0
0
Jenkinsdevops~10 mins

Workspace cleanup in Jenkins - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to delete all files in the Jenkins workspace.

Jenkins
steps.sh 'rm -rf [1]/*'
Drag options to blanks, or click blank then click option'
A${WORKSPACE}
Bworkspace
C/var/lib/jenkins/workspace
D/tmp
Attempts:
3 left
💡 Hint
Common Mistakes
Using a hardcoded path instead of the workspace variable.
Using a relative path that may not point to the workspace.
2fill in blank
medium

Complete the Jenkins pipeline step to clean the workspace before starting the build.

Jenkins
pipeline {
  agent any
  stages {
    stage('Cleanup') {
      steps {
        [1]()
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Ash 'rm -rf *'
BcleanWs
CdeleteDir
DworkspaceCleanup
Attempts:
3 left
💡 Hint
Common Mistakes
Using shell commands directly instead of the pipeline step.
Using deleteDir() which deletes the current directory but may not clean all workspace files.
3fill in blank
hard

Fix the error in the shell command to clean the workspace safely.

Jenkins
sh 'rm -rf [1]'
Drag options to blanks, or click blank then click option'
A${WORKSPACE}/*
B${WORKSPACE}
C/workspace/*
D/tmp/*
Attempts:
3 left
💡 Hint
Common Mistakes
Deleting the workspace folder itself causing Jenkins to fail.
Using incorrect or hardcoded paths.
4fill in blank
hard

Fill both blanks to create a post-build step that cleans the workspace only if the build fails.

Jenkins
post {
  failure {
    steps {
      [1]()
      sh 'rm -rf [2]/*'
    }
  }
}
Drag options to blanks, or click blank then click option'
AcleanWs
BdeleteDir
C${WORKSPACE}
D/tmp
Attempts:
3 left
💡 Hint
Common Mistakes
Using deleteDir() which may delete the workspace folder itself.
Using hardcoded paths instead of ${WORKSPACE}.
5fill in blank
hard

Fill all three blanks to define a pipeline that cleans workspace before and after the build.

Jenkins
pipeline {
  agent any
  stages {
    stage('Cleanup') {
      steps {
        [1]()
      }
    }
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
  }
  post {
    always {
      [2]()
      sh 'rm -rf [3]/*'
    }
  }
}
Drag options to blanks, or click blank then click option'
AcleanWs
BdeleteDir
C${WORKSPACE}
DcleanWorkspace
Attempts:
3 left
💡 Hint
Common Mistakes
Using different cleanup steps inconsistently.
Using hardcoded paths instead of environment variables.