Bird
Raised Fist0
Jenkinsdevops~10 mins

GitLab CI 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 GitLab CI job that runs a script.

Jenkins
job_name:
  script:
    - [1]
Drag options to blanks, or click blank then click option'
Aecho Hello World
Brun echo Hello
Cprint('Hello World')
Dexecute echo Hello
Attempts:
3 left
💡 Hint
Common Mistakes
Using programming language syntax instead of shell commands.
Adding extra keywords like 'run' or 'execute' which are not valid here.
2fill in blank
medium

Complete the code to specify the stage for a GitLab CI job.

Jenkins
job_name:
  stage: [1]
  script:
    - echo Running job
Drag options to blanks, or click blank then click option'
Abuild
Bexecute
Crun
Ddeploy
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid stage names like 'execute' or 'run'.
Confusing stage with script commands.
3fill in blank
hard

Fix the error in the GitLab CI job to correctly specify the image to use.

Jenkins
job_name:
  image: [1]
  script:
    - echo Hello
Drag options to blanks, or click blank then click option'
Adocker image:latest
Bdocker image
Calpine:latest
Ddocker_latest
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces in the image name.
Using underscores instead of colons.
4fill in blank
hard

Fill both blanks to create a GitLab CI job that runs only on the master branch and uses a specific runner tag.

Jenkins
job_name:
  script:
    - echo Deploying
  only:
    - [1]
  tags:
    - [2]
Drag options to blanks, or click blank then click option'
Amaster
Bmain
Cdocker-runner
Dshell-runner
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect branch names.
Using runner tags that do not exist.
5fill in blank
hard

Fill all three blanks to define a GitLab CI job with a cache path, a before_script, and a retry policy.

Jenkins
job_name:
  before_script:
    - [1]
  script:
    - echo Build
  cache:
    paths:
      - [2]
  retry: [3]
Drag options to blanks, or click blank then click option'
Anpm install
Bnode_modules/
C2
Dnpm run build
Attempts:
3 left
💡 Hint
Common Mistakes
Putting main build commands in before_script.
Using invalid cache paths.
Setting retry to a non-numeric value.

Practice

(1/5)
1. Which statement best describes the main difference between Jenkins and GitLab CI?
easy
A. Jenkins cannot automate building and testing.
B. GitLab CI has more plugins than Jenkins.
C. GitLab CI is easier to start with if you already use GitLab for your code.
D. Jenkins is only for deployment, not for testing.

Solution

  1. Step 1: Understand GitLab CI's integration

    GitLab CI is built into GitLab, making it simpler to start if your code is hosted there.
  2. Step 2: Compare Jenkins capabilities

    Jenkins offers more flexibility and plugins but requires more setup.
  3. Final Answer:

    GitLab CI is easier to start with if you already use GitLab for your code. -> Option C
  4. Quick Check:

    GitLab CI simpler start = B [OK]
Hint: GitLab CI is simpler if your code is on GitLab [OK]
Common Mistakes:
  • Thinking Jenkins cannot automate testing
  • Assuming GitLab CI has more plugins
  • Believing Jenkins is only for deployment
2. Which of the following is the correct way to define a simple Jenkins pipeline step that echoes 'Hello World'?
easy
A. pipeline { stages { stage('Example') { steps { echo 'Hello World' } } } }
B. pipeline { steps { stage('Example') { echo 'Hello World' } } }
C. pipeline { stage('Example') { steps { print('Hello World') } } }
D. pipeline { stages { step('Example') { echo 'Hello World' } } }

Solution

  1. Step 1: Recall Jenkins pipeline syntax

    A Jenkins pipeline requires 'stages' containing 'stage' blocks, each with 'steps'. The echo command is inside steps.
  2. Step 2: Identify correct syntax

    pipeline { stages { stage('Example') { steps { echo 'Hello World' } } } } correctly nests stages, stage, steps, and uses echo properly.
  3. Final Answer:

    pipeline { stages { stage('Example') { steps { echo 'Hello World' } } } } -> Option A
  4. Quick Check:

    Correct Jenkins pipeline syntax = A [OK]
Hint: Remember stages > stage > steps > commands in Jenkins pipeline [OK]
Common Mistakes:
  • Placing steps outside stage
  • Using print instead of echo
  • Misnaming stage as step
3. Given this Jenkins pipeline snippet, what will be the output in the console?
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
    stage('Test') {
      steps {
        echo 'Testing...'
      }
    }
  }
}
medium
A. Build stage skipped, only Testing runs
B. Building...\nTesting...
C. Testing...\nBuilding...
D. Syntax error, pipeline fails

Solution

  1. Step 1: Analyze pipeline stages order

    The pipeline runs stages in order: first 'Build', then 'Test'. Each stage echoes its message.
  2. Step 2: Determine console output

    The console will show 'Building...' first, then 'Testing...'.
  3. Final Answer:

    Building...\nTesting... -> Option B
  4. Quick Check:

    Stages run sequentially = C [OK]
Hint: Jenkins stages run in order, echo outputs in sequence [OK]
Common Mistakes:
  • Assuming stages run in parallel by default
  • Mixing order of outputs
  • Thinking pipeline syntax is invalid
4. You have this Jenkins pipeline snippet:
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
    stage('Test') {
      step {
        echo 'Testing...'
      }
    }
  }
}
What is the problem with this pipeline?
medium
A. The 'Test' stage uses 'step' instead of 'steps', causing a syntax error.
B. The 'Build' stage is missing an agent.
C. The echo command is invalid in Jenkins pipelines.
D. Stages must be defined outside the pipeline block.

Solution

  1. Step 1: Check stage syntax

    Each stage must have a 'steps' block, not 'step'. The 'Test' stage incorrectly uses 'step'.
  2. Step 2: Understand Jenkins syntax rules

    This causes a syntax error because Jenkins expects 'steps' to group commands.
  3. Final Answer:

    The 'Test' stage uses 'step' instead of 'steps', causing a syntax error. -> Option A
  4. Quick Check:

    Use 'steps' block in stages = A [OK]
Hint: Stages require 'steps' block, not 'step' [OK]
Common Mistakes:
  • Confusing 'step' and 'steps'
  • Thinking echo is invalid
  • Misplacing stages outside pipeline
5. You want to migrate a simple GitLab CI pipeline to Jenkins. The GitLab CI YAML is:
stages:
  - build
  - test

build_job:
  stage: build
  script:
    - echo "Building..."

test_job:
  stage: test
  script:
    - echo "Testing..."
Which Jenkins pipeline best replicates this behavior?
hard
A. pipeline { agent any stages { stage('build') { steps { print('Building...') } } stage('test') { steps { print('Testing...') } } } }
B. pipeline { agent any steps { echo 'Building...' echo 'Testing...' } }
C. pipeline { agent any stages { stage('build') { step { echo 'Building...' } } stage('test') { step { echo 'Testing...' } } } }
D. pipeline { agent any stages { stage('build') { steps { echo 'Building...' } } stage('test') { steps { echo 'Testing...' } } } }

Solution

  1. Step 1: Map GitLab stages to Jenkins stages

    GitLab stages 'build' and 'test' correspond to Jenkins stages named 'build' and 'test'.
  2. Step 2: Use correct Jenkins syntax

    Each stage must have a 'steps' block with echo commands to replicate the script commands.
  3. Final Answer:

    Jenkins pipeline with stages 'build' and 'test' each having steps with echo commands. -> Option D
  4. Quick Check:

    Match GitLab stages with Jenkins stages and steps = D [OK]
Hint: Translate GitLab stages to Jenkins stages with steps and echo [OK]
Common Mistakes:
  • Using 'step' instead of 'steps'
  • Using print instead of echo
  • Putting all commands in one steps block without stages
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