Bird
Raised Fist0
Jenkinsdevops~10 mins

Jenkins in the CI/CD ecosystem - Interactive Code Practice

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

Complete the code to define a Jenkins pipeline that runs on any available agent.

Jenkins
pipeline {
  agent [1]
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A'any'
Bnone
C'all'
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around 'any' which causes syntax error
Using 'all' or 'none' which are invalid agent values
2fill in blank
medium

Complete the code to trigger a Jenkins pipeline using periodic SCM polling.

Jenkins
pipeline {
  agent any
  triggers {
    pollSCM('[1]')
  }
  stages {
    stage('Test') {
      steps {
        echo 'Testing...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Arefs/heads/main
BH/5 * * * *
C*/5 * * * *
Dmain
Attempts:
3 left
💡 Hint
Common Mistakes
Using branch specifiers like 'refs/heads/main' or 'main', which are invalid cron expressions for pollSCM
Using '*/5 * * * *' without hashing, which can overload Jenkins at fixed intervals
3fill in blank
hard

Fix the error in the Jenkins pipeline syntax to correctly define environment variables.

Jenkins
pipeline {
  agent any
  environment {
    PATH = '[1]'
  }
  stages {
    stage('Deploy') {
      steps {
        echo "Deploying with PATH: $PATH"
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A/usr/local/bin:$PATH
BPATH:/usr/bin
CPATH:/usr/local/bin
D/usr/bin:$PATH
Attempts:
3 left
💡 Hint
Common Mistakes
Adding 'PATH=' inside the value which duplicates the key
Not including existing $PATH causing path loss
4fill in blank
hard

Fill both blanks to create a Jenkins pipeline stage that runs a shell command and archives the artifacts.

Jenkins
stage('Build') {
  steps {
    sh '[1]'
    archiveArtifacts '[2]'
  }
}
Drag options to blanks, or click blank then click option'
Amake build
Bmake test
C**/target/*.jar
D**/build/*.jar
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'make test' which runs tests but does not build
Archiving wrong artifact paths causing no files saved
5fill in blank
hard

Fill all three blanks to define a Jenkins pipeline that checks out code, runs tests, and sends a notification.

Jenkins
pipeline {
  agent any
  stages {
    stage('Checkout') {
      steps {
        [1] 'https://github.com/example/repo.git'
      }
    }
    stage('Test') {
      steps {
        sh '[2]'
      }
    }
    stage('Notify') {
      steps {
        [3] 'Build completed successfully'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Agit
Bmake test
Cecho
Dcheckout
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'checkout' instead of 'git' for cloning
Running wrong shell commands for tests
Using 'git' or 'checkout' for notification step

Practice

(1/5)
1. What is the primary role of Jenkins in the CI/CD ecosystem?
easy
A. Automate building, testing, and deploying software
B. Write application code
C. Design user interfaces
D. Manage database schemas

Solution

  1. Step 1: Understand Jenkins purpose

    Jenkins is a tool designed to automate software processes like building, testing, and deployment.
  2. Step 2: Compare options with Jenkins role

    Only Automate building, testing, and deploying software matches Jenkins' automation role in CI/CD; others relate to unrelated tasks.
  3. Final Answer:

    Automate building, testing, and deploying software -> Option A
  4. Quick Check:

    Jenkins automates CI/CD tasks = A [OK]
Hint: Jenkins automates software delivery steps [OK]
Common Mistakes:
  • Confusing Jenkins with coding or UI design tools
  • Thinking Jenkins manages databases
  • Assuming Jenkins writes application code
2. Which of the following is the correct syntax to define a simple Jenkins pipeline in a Jenkinsfile?
easy
A. job { steps { echo 'Building...' } }
B. build { steps { echo 'Building...' } }
C. pipeline: { stage('Build') { echo 'Building...' } }
D. pipeline { agent any stages { stage('Build') { steps { echo 'Building...' } } } }

Solution

  1. Step 1: Review Jenkins pipeline syntax

    The correct Jenkins pipeline uses the 'pipeline' block with 'agent' and 'stages' sections.
  2. Step 2: Match syntax with options

    pipeline { agent any stages { stage('Build') { steps { echo 'Building...' } } } } correctly shows the pipeline structure with agent, stages, and steps. Others have invalid or incomplete syntax.
  3. Final Answer:

    Correct Jenkins pipeline syntax with agent and stages -> Option D
  4. Quick Check:

    Valid Jenkinsfile uses 'pipeline' block = D [OK]
Hint: Look for 'pipeline', 'agent', and 'stages' keywords [OK]
Common Mistakes:
  • Missing 'agent' block in pipeline
  • Using 'build' or 'job' instead of 'pipeline'
  • Incorrect block nesting or missing braces
3. Given this Jenkins pipeline snippet, what will be the output when the pipeline runs?
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        echo 'Starting tests'
        script {
          def result = 2 + 3
          echo "Result is ${result}"
        }
      }
    }
  }
}
medium
A. Starting tests Result is ${result}
B. Starting tests Result is 5
C. Starting tests Result is 23
D. Syntax error in pipeline

Solution

  1. Step 1: Understand pipeline script block execution

    The 'script' block allows Groovy code execution; 'def result = 2 + 3' calculates 5.
  2. Step 2: Analyze echo statements

    First echo prints 'Starting tests', second prints 'Result is 5' using string interpolation.
  3. Final Answer:

    Starting tests Result is 5 -> Option B
  4. Quick Check:

    Groovy evaluates expressions inside ${} = C [OK]
Hint: Groovy evaluates ${} inside double quotes [OK]
Common Mistakes:
  • Treating ${result} as plain text
  • Concatenating numbers as strings
  • Assuming syntax error due to script block
4. You have this Jenkins pipeline snippet:
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
  }
  stages {
    stage('Test') {
      steps {
        echo 'Testing...'
      }
    }
  }
}

What is the problem with this pipeline?
medium
A. Multiple 'stages' blocks are not allowed in one pipeline
B. Missing 'agent' declaration
C. Echo commands are invalid in Jenkinsfile
D. Pipeline must have at least three stages

Solution

  1. Step 1: Review pipeline structure rules

    A Jenkins pipeline can have only one 'stages' block containing multiple 'stage' blocks.
  2. Step 2: Identify error in given pipeline

    Here, there are two separate 'stages' blocks, which is invalid syntax.
  3. Final Answer:

    Multiple 'stages' blocks are not allowed in one pipeline -> Option A
  4. Quick Check:

    Only one 'stages' block per pipeline = B [OK]
Hint: Only one 'stages' block allowed in Jenkinsfile [OK]
Common Mistakes:
  • Thinking multiple 'stages' blocks are valid
  • Confusing missing agent with stages error
  • Assuming echo commands cause errors
5. You want to create a Jenkins pipeline that builds your project only if the branch is 'main' and runs tests on all branches. Which pipeline snippet correctly implements this logic?
pipeline {
  agent any
  stages {
    stage('Build') {
      when {
        branch 'main'
      }
      steps {
        echo 'Building main branch'
      }
    }
    stage('Test') {
      steps {
        echo 'Running tests'
      }
    }
  }
}
hard
A. The pipeline builds and tests only on 'main' branch
B. The pipeline builds on all branches and tests only on 'main'
C. The pipeline builds only on 'main' branch and tests on all branches as required
D. The pipeline builds and tests on all branches without conditions

Solution

  1. Step 1: Understand 'when' condition in Build stage

    The 'when { branch 'main' }' condition restricts the Build stage to run only on the 'main' branch.
  2. Step 2: Analyze Test stage behavior

    The Test stage has no 'when' condition, so it runs on all branches.
  3. Final Answer:

    The pipeline builds only on 'main' branch and tests on all branches as required -> Option C
  4. Quick Check:

    'when' limits build; test runs always = A [OK]
Hint: Use 'when' to limit stages by branch [OK]
Common Mistakes:
  • Assuming all stages run on all branches
  • Misplacing 'when' condition on Test stage
  • Confusing branch names or conditions
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard