CI/CD - Jenkins pipelines - multichoice questions
Question 1
Choose the correct sentence(s) for an Executor:
- A slot for execution of work defined by a Pipeline.
- Executor is the central coordinating process which stores configuration, loads plugins, and renders the various user interfaces for Jenkins.
- A Node may have zero or more executors configured.
- A user-configured description of work which Jenkins should perform.
- The number of executors in a node define how many concurrent jobs are able to execute on that Node.
Question 2
Given the stage:
stage("Determine new version") {
steps {
sh "docker-compose exec -T php-fpm composer --no-ansi --no-interaction tests-ci"
}
post {
always {
junit "build/junit/*.xml"
step([
$class : "CloverPublisher",
cloverReportDir : "build/coverage",
cloverReportFileName: "clover.xml"
])
}
}
}
Which of the following lines should be added to the stage{}
scope such that the stage would be executed only when the job was originated from branch main
?
- Add
branch { "main" }
. - Add
return "main"
. - Add
when { branch "main" }
. - None of the above
Question 3
Given:
pipeline {
agent any
environment {
TEST_PREFIX = "test"
TEST_IMAGE = "${env.TEST_PREFIX}:${env.BUILD_NUMBER}"
REGISTRY_AUTH = credentials("docker-registry")
IS_NEW_VERSION = "YES"
REGISTRY_ADDRESS = "hub.docker.io"
}
stages {
stage("Login") {
when {
environment name: "IS_NEW_VERSION", value: "YES"
}
steps {
script {
env.IS_NEW_VERSION = sh(returnStdout: true, script: echo 'NO'").trim()
}
sh "docker login -u=$REGISTRY_AUTH_USR -p=$REGISTRY_AUTH_PSW ${env.REGISTRY_ADDRESS}"
}
}
stage("Sample stage") {
when {
environment name: "IS_NEW_VERSION", value: "YES"
}
steps {
sh "echo worked!"
}
}
}
}
Assuming the Login
stage has been executed successfully, will the Sample stage
stage be executed?
- Yes
- No
- Depending on the value of the
TEST_IMAGE
variable - None of the above
Question 4
Given the following pipeline:
pipeline {
agent any
environment {
IS_NEW_VERSION = "YES"
}
stages {
stage("Deploy to production") {
when {
environment name: "IS_NEW_VERSION", value: "YES"
}
steps {
sh "exit 5"
}
post {
success {
slackSend(
teamDomain: "${env.SLACK_TEAM_DOMAIN}",
token: "${env.SLACK_TOKEN}",
channel: "${env.SLACK_CHANNEL}",
color: "good",
message: "${env.STACK_PREFIX} production deploy: *${env.DEPLOY_VERSION}*. <${env.DEPLOY_URL}|Access service> - <${env.BUILD_URL}|Check build>"
)
}
failure {
slackSend(
teamDomain: "${env.SLACK_TEAM_DOMAIN}",
token: "${env.SLACK_TOKEN}",
channel: "${env.SLACK_CHANNEL}",
color: "danger",
message: "${env.STACK_PREFIX} production deploy failed: *${env.DEPLOY_VERSION}*. <${env.BUILD_URL}|Check build>"
)
}
}
}
}
}
Assuming the Slack Notification was installed and configured properly in the Jenkins server:
- Success message would be sent to the Slack channel
- Failure message would be sent to the Slack channel
- The stage wouldn't be running
- None of the above
Question 5
What is the primary purpose of discarding concurrent builds in a deployment pipeline?
- To speed up the deployment process by deploying multiple builds simultaneously.
- To ensure that only one build is deployed to production at a time.
- To create redundancy in case of deployment failures.
- To test the stability of the production environment with multiple builds.
Question 6
You have set up a Jenkins pipline which pushes an image to ERC. Recently, you've noticed that sometimes the pipeline gets stuck due to unavailability or ECR:
The push refers to repository [xxxxxxxxxxx.dkr.ecr.ca-central-1.amazonaws.com/reponame]
714c1b96dd83: Retrying in 1 second
d2cdc77dd068: Retrying in 1 second
30aad807caf5: Retrying in 1 second
0559774c4ea2: Retrying in 1 second
285b8616682f: Retrying in 1 second
4aeea0ec2b15: Waiting
1b1312f842d8: Waiting
c310009e0ef3: Waiting
a48777e566d3: Waiting
2a0c9f28029a: Waiting
This issues resulted and prolonged blocking of your build and deployment pipelines.
How can you address this issue?
- Disable concurrent builds:
options { disableConcurrentBuilds() }
- Add a build timeout:
options { timeout(time: 25, unit: 'MINUTES') }
- Preserve build stashes:
options { preserveStashes(buildCount: 5) }
- Open a support ticket to AWS team
Question 7
You have set up a Jenkins server on a private subnet in your organization's network. Your development team uses GitHub for version control, and you want to trigger Jenkins jobs automatically when code is pushed to the GitHub repository. However, you're facing issues with triggering the jobs due to the Jenkins server's location on the private subnet.
Which method can you use to address this issue effectively?
- Configure GitHub webhooks to trigger Jenkins jobs.
- Generate SSH keys and establish a secure connection between your GitHub repository and the Jenkins server.
- Use GitHub Actions.
- Set up a polling mechanism in Jenkins to periodically check the GitHub repository for code changes.