0
0
Jenkinsdevops~10 mins

Parameterized builds 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 string parameter named 'ENV' in a Jenkins pipeline.

Jenkins
parameters {
    string(name: '[1]', defaultValue: 'dev', description: 'Environment')
}
Drag options to blanks, or click blank then click option'
AENV
Benvironment
CenvVar
Denv
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or different names like 'env' or 'environment' which won't match the parameter usage.
2fill in blank
medium

Complete the code to access the parameter 'ENV' inside the Jenkins pipeline script.

Jenkins
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                echo "Building for environment: [1]"
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
Abuild.ENV
Bparams.ENV
Cparameters.ENV
Denv.ENV
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'env.ENV' which refers to environment variables, not parameters.
Using 'parameters.ENV' which is not valid syntax.
3fill in blank
hard

Fix the error in the parameter definition to correctly define a boolean parameter named 'RUN_TESTS'.

Jenkins
parameters {
    booleanParam(name: '[1]', defaultValue: true, description: 'Run tests')
}
Drag options to blanks, or click blank then click option'
ARUN_TESTS
BRunTests
Crun_tests
DrunTests
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase or lowercase names that don't match the parameter usage.
4fill in blank
hard

Fill both blanks to define a choice parameter named 'DEPLOY_ENV' with options 'dev', 'staging', and 'prod'.

Jenkins
parameters {
    choice(name: '[1]', choices: [2], description: 'Select deployment environment')
}
Drag options to blanks, or click blank then click option'
ADEPLOY_ENV
B['dev', 'staging', 'prod']
C['prod', 'staging', 'dev']
DDEPLOYENV
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names or wrong order of choices.
Not using a list format for choices.
5fill in blank
hard

Fill all three blanks to create a pipeline that uses a string parameter 'VERSION', checks if it is not empty, and echoes the version.

Jenkins
pipeline {
    agent any
    parameters {
        string(name: '[1]', defaultValue: '', description: 'Version to build')
    }
    stages {
        stage('Check Version') {
            steps {
                script {
                    if (params.[2] [3] '') {
                        echo "Building version: ${params.VERSION}"
                    } else {
                        error 'Version parameter is empty!'
                    }
                }
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
AVERSION
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' causing the logic to invert.
Mismatching parameter names between definition and usage.