0
0
Jenkinsdevops~10 mins

Idempotent pipeline steps 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 define a Jenkins pipeline step that runs a shell command idempotently.

Jenkins
stage('Build') {
  steps {
    sh '[1]'
  }
}
Drag options to blanks, or click blank then click option'
Aecho 'Building...'
Brm -rf *
Cexit 1
Dmkdir /tmp
Attempts:
3 left
💡 Hint
Common Mistakes
Using commands that delete or modify files like 'rm -rf *' which are not idempotent.
Using commands that exit with error causing pipeline failure.
2fill in blank
medium

Complete the code to check if a directory exists before creating it, ensuring idempotency.

Jenkins
stage('Prepare') {
  steps {
    sh 'if [ ! -d /app ]; then [1] /app; fi'
  }
}
Drag options to blanks, or click blank then click option'
Amkdir
Brm -rf
Ctouch
Dcd
Attempts:
3 left
💡 Hint
Common Mistakes
Using rm -rf which deletes files and is not idempotent.
Using touch which creates files, not directories.
3fill in blank
hard

Fix the error in the Jenkins pipeline step to make the shell command idempotent.

Jenkins
stage('Deploy') {
  steps {
    sh '[1]'
  }
}
Drag options to blanks, or click blank then click option'
Arm -rf /var/www/html/*
Brsync -a /src/ /var/www/html/
Ccp -r /src/* /var/www/html/
Dexit 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using rm -rf which deletes all files and is not idempotent.
Using cp -r which copies files but may overwrite unnecessarily.
4fill in blank
hard

Fill both blanks to create an idempotent Jenkins pipeline step that installs a package only if missing.

Jenkins
stage('Install') {
  steps {
    sh 'if ! dpkg -l | grep -q [1]; then sudo [2] [1]; fi'
  }
}
Drag options to blanks, or click blank then click option'
Acurl
Bapt-get install
Cgit
Dvim
Attempts:
3 left
💡 Hint
Common Mistakes
Using commands that do not check package presence before installing.
Using package names that are not installed by apt-get.
5fill in blank
hard

Fill all three blanks to create an idempotent Jenkins pipeline step that updates a config file only if a setting is missing.

Jenkins
stage('Configure') {
  steps {
    sh '''
      if ! grep -q '[1]' /etc/app/config.conf; then
        echo '[1]=[2]' >> [3]
      fi
    '''
  }
}
Drag options to blanks, or click blank then click option'
Amax_connections
B100
C/etc/app/config.conf
Dtimeout
Attempts:
3 left
💡 Hint
Common Mistakes
Appending the setting without checking if it exists, causing duplicates.
Using wrong file path or key names.