Complete the code to define a Jenkins pipeline step that runs a shell command idempotently.
stage('Build') { steps { sh '[1]' } }
The echo 'Building...' command is safe and idempotent because it only prints text without changing the system state.
Complete the code to check if a directory exists before creating it, ensuring idempotency.
stage('Prepare') { steps { sh 'if [ ! -d /app ]; then [1] /app; fi' } }
rm -rf which deletes files and is not idempotent.touch which creates files, not directories.The mkdir command creates the directory only if it does not exist, making the step idempotent.
Fix the error in the Jenkins pipeline step to make the shell command idempotent.
stage('Deploy') { steps { sh '[1]' } }
rm -rf which deletes all files and is not idempotent.cp -r which copies files but may overwrite unnecessarily.The rsync -a command copies files efficiently and only updates changed files, making it idempotent.
Fill both blanks to create an idempotent Jenkins pipeline step that installs a package only if missing.
stage('Install') { steps { sh 'if ! dpkg -l | grep -q [1]; then sudo [2] [1]; fi' } }
The command checks if git is installed, and if not, installs it using apt-get install. This makes the step idempotent.
Fill all three blanks to create an idempotent Jenkins pipeline step that updates a config file only if a setting is missing.
stage('Configure') { steps { sh ''' if ! grep -q '[1]' /etc/app/config.conf; then echo '[1]=[2]' >> [3] fi ''' } }
This step checks if the setting max_connections is in the config file. If missing, it appends max_connections=100 to /etc/app/config.conf. This ensures idempotency by not duplicating the setting.