0
0
Jenkinsdevops~10 mins

Why parameterized pipelines matter in Jenkins - Test Your Understanding

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 in a Jenkins pipeline.

Jenkins
parameters {
    string(name: '[1]', defaultValue: 'world', description: 'Who to greet?')
}
Drag options to blanks, or click blank then click option'
AUSER
BGREETING
CTARGET
DNAME
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic or unrelated parameter name.
Forgetting to define parameters block.
2fill in blank
medium

Complete the code to access the parameter value inside the pipeline script.

Jenkins
pipeline {
    agent any
    parameters {
        string(name: 'NAME', defaultValue: 'world', description: 'Who to greet?')
    }
    stages {
        stage('Greet') {
            steps {
                echo "Hello, [1]!"
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
Aparams.NAME
Benv.NAME
CNAME
Dinput.NAME
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'env' instead of 'params' to access parameters.
Using the parameter name directly without 'params'.
3fill in blank
hard

Fix the error in the pipeline code by completing the missing keyword to define parameters.

Jenkins
pipeline {
    agent any
    [1] {
        string(name: 'ENV', defaultValue: 'dev', description: 'Environment')
    }
    stages {
        stage('Deploy') {
            steps {
                echo "Deploying to ${params.ENV}"
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
Aoptions
Benvironment
Cparameters
Dtriggers
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'environment' instead of 'parameters'.
Omitting the parameters block entirely.
4fill in blank
hard

Fill both blanks to create a boolean parameter and use it in a conditional step.

Jenkins
parameters {
    booleanParam(name: '[1]', defaultValue: true, description: 'Run tests?')
}
stages {
    stage('Test') {
        when {
            expression { return params.[2] }
        }
        steps {
            echo 'Running tests...'
        }
    }
}
Drag options to blanks, or click blank then click option'
ARUN_TESTS
BrunTests
Drun_tests
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names or cases for the parameter in definition and usage.
Forgetting to use 'params.' prefix in the expression.
5fill in blank
hard

Fill all three blanks to define a choice parameter and print the selected option.

Jenkins
parameters {
    choice(name: '[1]', choices: ['dev', '[2]', 'prod'], description: 'Select environment')
}
stages {
    stage('Print Env') {
        steps {
            echo "Selected environment is: ${params.[3]"
        }
    }
}
Drag options to blanks, or click blank then click option'
AENVIRONMENT
Bstaging
Denvironment
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching parameter names in definition and usage.
Forgetting to include all choices in the list.