0
0
Jenkinsdevops~10 mins

Jenkinsfile per branch - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to checkout the current branch in Jenkins pipeline.

Jenkins
checkout([$class: 'GitSCM', branches: [[name: '[1]']], userRemoteConfigs: [[url: 'https://github.com/example/repo.git']]])
Drag options to blanks, or click blank then click option'
Amain
Bmaster
Cenv.BRANCH_NAME
Ddevelop
Attempts:
3 left
💡 Hint
Common Mistakes
Hardcoding branch name instead of using environment variable.
Using incorrect variable names.
2fill in blank
medium

Complete the code to select the Jenkinsfile path based on the branch name.

Jenkins
def jenkinsfilePath = (env.BRANCH_NAME == 'main') ? '[1]' : 'Jenkinsfile.dev'
Drag options to blanks, or click blank then click option'
AJenkinsfile
BJenkinsfile.main
CJenkinsfile.prod
DJenkinsfile.master
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect Jenkinsfile names.
Confusing branch names with Jenkinsfile names.
3fill in blank
hard

Fix the error in the pipeline script to load the correct Jenkinsfile per branch.

Jenkins
pipeline {
  agent any
  stages {
    stage('Checkout') {
      steps {
        checkout scm
      }
    }
    stage('Build') {
      steps {
        load '[1]'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
AJenkinsfile-${env.BRANCH_NAME}
BJenkinsfile.${env.BRANCH_NAME}
CJenkinsfile
DJenkinsfile_${env.BRANCH_NAME}
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot notation inside string interpolation incorrectly.
Using underscores or dots instead of dash.
4fill in blank
hard

Fill both blanks to define a pipeline that loads a Jenkinsfile based on the branch name and runs it.

Jenkins
def file = 'Jenkinsfile[1][2]'
load file
Drag options to blanks, or click blank then click option'
A-
B_
Cenv.BRANCH_NAME
DBRANCH_NAME
Attempts:
3 left
💡 Hint
Common Mistakes
Using underscore instead of dash.
Using undefined variable names.
5fill in blank
hard

Fill all three blanks to create a Jenkins pipeline that checks out the current branch, selects the Jenkinsfile path, and loads it.

Jenkins
pipeline {
  agent any
  stages {
    stage('Checkout') {
      steps {
        checkout([$class: 'GitSCM', branches: [[name: '[1]']], userRemoteConfigs: [[url: 'https://github.com/example/repo.git']]])
      }
    }
    stage('Load Jenkinsfile') {
      steps {
        def file = '[2][3]'
        load file
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Aenv.BRANCH_NAME
BJenkinsfile-
CJenkinsfile
Denv.BRANCH
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect environment variable names.
Not matching branch name in checkout and Jenkinsfile path.