0
0
Jenkinsdevops~10 mins

Conditional deployment logic 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 run deployment only if the branch is 'main'.

Jenkins
if (env.BRANCH_NAME == '[1]') {
  echo 'Deploying to production...'
}
Drag options to blanks, or click blank then click option'
Adevelop
Bfeature
Cmain
Dtest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'develop' or other branch names instead of 'main'.
Forgetting to compare the branch name as a string.
2fill in blank
medium

Complete the code to skip deployment if the build is triggered by a pull request.

Jenkins
if (env.CHANGE_ID == [1]) {
  echo 'Deploying...'
} else {
  echo 'Skipping deployment for pull request.'
}
Drag options to blanks, or click blank then click option'
Atrue
Bnull
C0
D''
Attempts:
3 left
💡 Hint
Common Mistakes
Using empty string '' instead of null.
Using 0 or true which are not valid for this check.
3fill in blank
hard

Fix the error in the condition to deploy only on 'release' branch and not on pull requests.

Jenkins
if (env.BRANCH_NAME == '[1]' && env.CHANGE_ID == null) {
  echo 'Deploying release build...'
}
Drag options to blanks, or click blank then click option'
Afeature
Bmain
Cdevelop
Drelease
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'main' or 'develop' instead of 'release'.
Not checking for pull request correctly.
4fill in blank
hard

Fill both blanks to deploy only if the branch is 'main' and the build is not a pull request.

Jenkins
if (env.BRANCH_NAME == '[1]' && env.CHANGE_ID == [2]) {
  echo 'Deploying to production...'
}
Drag options to blanks, or click blank then click option'
Amain
Bnull
Cdevelop
D''
Attempts:
3 left
💡 Hint
Common Mistakes
Using empty string '' instead of null for CHANGE_ID.
Using wrong branch name.
5fill in blank
hard

Fill all three blanks to deploy only if the branch is 'develop', the build is not a pull request, and the environment is 'staging'.

Jenkins
if (env.BRANCH_NAME == '[1]' && env.CHANGE_ID == [2] && env.ENVIRONMENT == '[3]') {
  echo 'Deploying to staging environment...'
}
Drag options to blanks, or click blank then click option'
Adevelop
Bnull
Cstaging
Dproduction
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'production' instead of 'staging' for environment.
Using empty string '' instead of null for CHANGE_ID.
Using wrong branch name.