Bird
Raised Fist0
Jenkinsdevops~10 mins

CircleCI comparison in Jenkins - 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 stage that runs tests.

Jenkins
stage('Test') {
    steps {
        [1] 'runTests.sh'
    }
}
Drag options to blanks, or click blank then click option'
Ash
Brun
Cexecute
Dscript
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' instead of 'sh' causes an error.
Using 'execute' is not a Jenkins step.
2fill in blank
medium

Complete the code to configure SCM polling with a cron schedule.

Jenkins
pipeline {
    agent any
    triggers {
        pollSCM('[1]')
    }
}
Drag options to blanks, or click blank then click option'
AH/5 * * * *
Bmain
C*/5 * * * *
Drefs/heads/main
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'main' or 'refs/heads/main' does not work; those are branch specifiers configured in SCM settings.
Cron schedules trigger polling regardless of branch; branch filters are set separately.
3fill in blank
hard

Fix the error in the Jenkinsfile to archive test results.

Jenkins
post {
    always {
        [1] artifacts: '**/test-results/*.xml', allowEmptyArchive: true
    }
}
Drag options to blanks, or click blank then click option'
AarchiveFiles
BarchiveArtifacts
Carchive
DsaveArtifacts
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'archive' causes a syntax error.
Using 'saveArtifacts' is not a Jenkins step.
4fill in blank
hard

Fill both blanks to define a Jenkins pipeline with environment variables and a build step.

Jenkins
pipeline {
    agent any
    environment {
        APP_ENV = '[1]'
    }
    stages {
        stage('Build') {
            steps {
                [2] 'build.sh'
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
Aproduction
Bsh
Cdevelopment
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' instead of 'sh' causes errors.
Setting APP_ENV to 'development' is valid but not the expected answer here.
5fill in blank
hard

Fill all three blanks to create a Jenkins pipeline that checks out code, runs tests, and archives results.

Jenkins
pipeline {
    agent any
    stages {
        stage('Checkout') {
            steps {
                [1] scm
            }
        }
        stage('Test') {
            steps {
                [2] 'runTests.sh'
            }
        }
    }
    post {
        always {
            [3] artifacts: '**/test-results/*.xml'
        }
    }
}
Drag options to blanks, or click blank then click option'
Acheckout
Bsh
CarchiveArtifacts
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' instead of 'sh' causes errors.
Using 'archive' instead of 'archiveArtifacts' causes errors.

Practice

(1/5)
1. Which statement best describes Jenkins compared to CircleCI?
easy
A. Jenkins is self-hosted and offers full control over the environment.
B. Jenkins is only cloud-based and easy to start with.
C. Jenkins does not support automation of builds and tests.
D. Jenkins requires no setup or management.

Solution

  1. Step 1: Understand Jenkins hosting model

    Jenkins is known for being self-hosted, meaning you install and manage it yourself.
  2. Step 2: Compare with CircleCI

    CircleCI is mostly cloud-based and easier to start with, unlike Jenkins which requires more setup.
  3. Final Answer:

    Jenkins is self-hosted and offers full control over the environment. -> Option A
  4. Quick Check:

    Jenkins = self-hosted, full control [OK]
Hint: Remember Jenkins = self-hosted control, CircleCI = cloud ease [OK]
Common Mistakes:
  • Thinking Jenkins is only cloud-based
  • Believing Jenkins requires no setup
  • Assuming Jenkins can't automate builds
2. Which Jenkins pipeline syntax is correct for a simple build step?
easy
A. pipeline { stages { stage('Build') { run { sh 'make' } } } }
B. pipeline { build { stage('Build') { steps { sh 'make' } } } }
C. pipeline { stages { step('Build') { sh 'make' } } }
D. pipeline { stages { stage('Build') { steps { sh 'make' } } } }

Solution

  1. Step 1: Identify correct pipeline block structure

    Jenkins pipelines use 'pipeline' with 'stages', each containing 'stage' and 'steps'.
  2. Step 2: Check syntax for build step

    The correct syntax uses 'stage' with 'steps' and inside 'steps' the shell command with 'sh'.
  3. Final Answer:

    pipeline { stages { stage('Build') { steps { sh 'make' } } } } -> Option D
  4. Quick Check:

    Correct pipeline syntax = pipeline { stages { stage('Build') { steps { sh 'make' } } } } [OK]
Hint: Remember stages contain stage blocks with steps inside [OK]
Common Mistakes:
  • Using 'build' instead of 'stages'
  • Replacing 'stage' with 'step'
  • Using 'run' instead of 'steps'
3. Given this Jenkins pipeline snippet, what will be the output if the shell command fails?
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        sh 'exit 1'
      }
    }
  }
}
medium
A. The pipeline will succeed because 'exit 1' is ignored.
B. The pipeline will continue to the next stage ignoring the failure.
C. The pipeline will fail and stop at the 'Test' stage.
D. The pipeline will retry the 'Test' stage automatically.

Solution

  1. Step 1: Understand shell command exit codes in Jenkins

    In Jenkins, a shell command returning non-zero exit code causes the stage to fail.
  2. Step 2: Analyze the pipeline behavior on failure

    The 'sh' step with 'exit 1' returns failure, so the pipeline stops at 'Test' stage.
  3. Final Answer:

    The pipeline will fail and stop at the 'Test' stage. -> Option C
  4. Quick Check:

    Non-zero exit code = pipeline failure [OK]
Hint: Non-zero shell exit stops Jenkins pipeline [OK]
Common Mistakes:
  • Assuming pipeline continues after failure
  • Thinking Jenkins ignores shell exit codes
  • Believing Jenkins retries automatically
4. You have a Jenkinsfile with this snippet:
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        sh 'make build'
      }
    }
  }
}

The build step fails but Jenkins shows success. What is the likely cause?
medium
A. The 'make build' command always returns zero exit code.
B. The 'sh' step uses 'returnStatus: true' but the status is not checked to detect failure.
C. The pipeline is configured to ignore all errors globally.
D. The 'sh' step is running in background and not waiting for completion.

Solution

  1. Step 1: Understand Jenkins 'sh' step behavior

    By default, 'sh' fails the build if the command returns non-zero exit code unless 'returnStatus: true' is used to handle it manually.
  2. Step 2: Identify why failure is ignored

    If 'returnStatus: true' is used but failure is ignored, likely the status is not checked to detect failure.
  3. Final Answer:

    The 'sh' step uses 'returnStatus: true' but the status is not checked to detect failure. -> Option B
  4. Quick Check:

    Missing returnStatus check causes unnoticed failures [OK]
Hint: Check 'returnStatus' to catch shell errors in Jenkins [OK]
Common Mistakes:
  • Assuming shell commands run in background
  • Believing Jenkins ignores errors by default
  • Thinking 'make build' always succeeds
5. You want to migrate a simple CircleCI config to Jenkins. CircleCI config uses:
version: 2.1
jobs:
  build:
    docker:
      - image: cimg/python:3.8
    steps:
      - checkout
      - run: python -m unittest discover
workflows:
  build_and_test:
    jobs:
      - build

Which Jenkins pipeline snippet best replicates this?
hard
A. pipeline { agent { docker { image 'cimg/python:3.8' } } stages { stage('Checkout') { steps { checkout scm } } stage('Test') { steps { sh 'python -m unittest discover' } } } }
B. pipeline { agent any stages { stage('Build') { steps { sh 'docker run cimg/python:3.8 python -m unittest discover' } } } }
C. pipeline { agent { label 'docker' } stages { stage('Test') { steps { sh 'python -m unittest discover' } } } }
D. pipeline { agent none stages { stage('Build') { steps { sh 'python -m unittest discover' } } } }

Solution

  1. Step 1: Map CircleCI docker image to Jenkins agent

    CircleCI uses a docker image for the job; Jenkins can specify a docker agent with the same image.
  2. Step 2: Replicate steps: checkout and run tests

    Jenkins needs a 'checkout scm' step and a shell command to run tests, matching CircleCI steps.
  3. Final Answer:

    pipeline { agent { docker { image 'cimg/python:3.8' } } stages { stage('Checkout') { steps { checkout scm } } stage('Test') { steps { sh 'python -m unittest discover' } } } } -> Option A
  4. Quick Check:

    Docker agent + checkout + test command = pipeline { agent { docker { image 'cimg/python:3.8' } } stages { stage('Checkout') { steps { checkout scm } } stage('Test') { steps { sh 'python -m unittest discover' } } } } [OK]
Hint: Use docker agent and separate checkout, test stages [OK]
Common Mistakes:
  • Running docker inside shell instead of agent
  • Missing checkout step
  • Using agent none or wrong label
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