0
0
Jenkinsdevops~10 mins

CI/CD tools landscape 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' when the step is building.
Leaving the stage name empty.
2fill in blank
medium

Complete the code to trigger the pipeline only when changes are pushed to the 'main' branch.

Jenkins
pipeline {
    agent any
    triggers {
        [1] {
            pollSCM('H/5 * * * *')
        }
    }
    stages {
        stage('Build') {
            steps {
                echo 'Building...'
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
ApollSCM
Bbranch
Ccron
DgithubPush
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cron' which triggers on a schedule, not on code changes.
Using 'branch' which is not a valid trigger keyword.
3fill in blank
hard

Fix the error in the Jenkinsfile snippet to correctly checkout code from Git.

Jenkins
pipeline {
    agent any
    stages {
        stage('Checkout') {
            steps {
                [1]([$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[url: 'https://github.com/example/repo.git']]])
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
Aclone
Bcheckout
CgitClone
DgitCheckout
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'gitCheckout' which is not a valid Jenkins step.
Using 'clone' which is a git command but not a Jenkins pipeline step.
4fill in blank
hard

Fill both blanks to create a post-build action that always sends an email notification.

Jenkins
post {
    [1] {
        mail to: 'team@example.com', subject: 'Build [2]', body: 'The build has finished.'
    }
}
Drag options to blanks, or click blank then click option'
Aalways
Bsuccess
Cfailure
Dunstable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'success' which only runs on successful builds.
Using 'failure' which only runs on failed builds.
5fill in blank
hard

Fill all three blanks to define an environment variable and use it in a shell step.

Jenkins
pipeline {
    agent any
    environment {
        [1] = '[2]'
    }
    stages {
        stage('Print Env') {
            steps {
                sh 'echo [3]'
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
AMY_VAR
BHelloWorld
C$MY_VAR
DGREETING
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable name with lowercase letters.
Not using '$' to reference the variable in shell.