0
0
Jenkinsdevops~10 mins

Hybrid CI/CD approaches 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 define a Jenkins pipeline stage named 'Build'.

Jenkins
stage('[1]') {
    steps {
        echo 'Building the project'
    }
}
Drag options to blanks, or click blank then click option'
ABuild
BTest
CDeploy
DClean
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong stage name like 'Test' instead of 'Build'.
2fill in blank
medium

Complete the code to trigger a Jenkins pipeline only when a commit is pushed to the 'main' branch.

Jenkins
pipeline {
    agent any
    triggers {
        pollSCM('[1]')
    }
    stages {
        stage('Build') {
            steps {
                echo 'Building...'
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
Amain
Brefs/heads/main
CH/5 * * * *
D*/15 * * * *
Attempts:
3 left
💡 Hint
Common Mistakes
Using branch names like 'refs/heads/main' as pollSCM argument.
3fill in blank
hard

Fix the error in the Jenkins pipeline code to correctly define an environment variable.

Jenkins
pipeline {
    agent any
    environment {
        VERSION = '[1]'
    }
    stages {
        stage('Build') {
            steps {
                echo "Version is $VERSION"
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
A"1.0.0"
B1.0.0
CVERSION=1.0.0
D'1.0.0'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning unquoted values causing syntax errors.
4fill in blank
hard

Fill both blanks to create a Jenkins pipeline stage that runs tests only if the build stage succeeds.

Jenkins
stage('Test') {
    when {
        [1] [2] 'Build'
    }
    steps {
        echo 'Running tests'
    }
}
Drag options to blanks, or click blank then click option'
Astage
Bbranch
Cequals
DnotEquals
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'branch' instead of 'stage' in the when condition.
5fill in blank
hard

Fill all three blanks to define a hybrid Jenkins pipeline that uses both scripted and declarative syntax.

Jenkins
pipeline {
    agent any
    stages {
        stage('Hybrid') {
            steps {
                script {
                    if (env.BRANCH_NAME == '[1]') {
                        echo '[2]'
                    } else {
                        echo '[3]'
                    }
                }
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
Amain
BRunning on main branch
CRunning on feature branch
Ddevelop
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong branch names or messages that don't match the condition.