0
0
Jenkinsdevops~20 mins

Jenkinsfile concept - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Jenkinsfile Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this Jenkins pipeline stage?
Consider this Jenkinsfile snippet. What will be printed in the console when the Build stage runs?
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building project...'
      }
    }
  }
}
ABuild stage started
BBuilding project...
CPipeline started
DNo output
Attempts:
2 left
💡 Hint
Look at the echo command inside the Build stage.
Configuration
intermediate
1:30remaining
Which Jenkinsfile syntax correctly defines a post-build action?
You want to send a notification only after the pipeline finishes, regardless of success or failure. Which Jenkinsfile snippet correctly uses the post section?
A
post {
  failure {
    echo 'Pipeline finished'
  }
}
B
post {
  success {
    echo 'Pipeline finished'
  }
}
C
post {
  finished {
    echo 'Pipeline finished'
  }
}
D
post {
  always {
    echo 'Pipeline finished'
  }
}
Attempts:
2 left
💡 Hint
The always block runs no matter what the pipeline result is.
🔀 Workflow
advanced
2:00remaining
What is the correct order of execution in this Jenkins pipeline?
Reorder the stages in the order they will execute in this Jenkinsfile:
Jenkins
pipeline {
  agent any
  stages {
    stage('Test') {
      steps { echo 'Testing...' }
    }
    stage('Build') {
      steps { echo 'Building...' }
    }
    stage('Deploy') {
      steps { echo 'Deploying...' }
    }
  }
}
A2,1,3
B1,2,3
C3,1,2
D2,3,1
Attempts:
2 left
💡 Hint
Stages run in the order they are defined in the Jenkinsfile.
Troubleshoot
advanced
1:30remaining
What error will this Jenkinsfile cause?
This Jenkinsfile snippet is used to run a shell command. What error will Jenkins report?
Jenkins
pipeline {
  agent any
  stages {
    stage('Run') {
      steps {
        sh 'echo Hello World'
      }
    }
  }
}
ATypeError: Invalid argument to sh step
BRuntimeError: Command not found
CNo error, prints 'Hello World'
DSyntaxError: Unexpected end of file (missing closing quote)
Attempts:
2 left
💡 Hint
Check the quotes around the shell command.
Best Practice
expert
2:30remaining
Which Jenkinsfile snippet correctly uses environment variables for secure credentials?
You want to use a secret password stored in Jenkins credentials inside your pipeline securely. Which snippet correctly accesses the secret?
A
steps {
  withCredentials([string(credentialsId: 'my-secret', variable: 'PASSWORD')]) {
    echo "Password is $PASSWORD"
  }
}
B
environment {
  PASSWORD = credentials('my-secret')
}

steps {
  echo "Password is $PASSWORD"
}
C
steps {
  echo "Password is ${env.my-secret}"
}
D
environment {
  PASSWORD = 'my-secret'
}
steps {
  echo "Password is $PASSWORD"
}
Attempts:
2 left
💡 Hint
Use the withCredentials step to access secrets safely.