Complete the code to define a string parameter in a Jenkins pipeline.
parameters {
string(name: '[1]', defaultValue: 'world', description: 'Who to greet?')
}The parameter name should be NAME to represent the input for the greeting.
Complete the code to access the parameter value inside the pipeline script.
pipeline {
agent any
parameters {
string(name: 'NAME', defaultValue: 'world', description: 'Who to greet?')
}
stages {
stage('Greet') {
steps {
echo "Hello, [1]!"
}
}
}
}In Jenkins pipelines, parameters are accessed using params.PARAMETER_NAME.
Fix the error in the pipeline code by completing the missing keyword to define parameters.
pipeline {
agent any
[1] {
string(name: 'ENV', defaultValue: 'dev', description: 'Environment')
}
stages {
stage('Deploy') {
steps {
echo "Deploying to ${params.ENV}"
}
}
}
}The parameters block defines input parameters for the pipeline.
Fill both blanks to create a boolean parameter and use it in a conditional step.
parameters {
booleanParam(name: '[1]', defaultValue: true, description: 'Run tests?')
}
stages {
stage('Test') {
when {
expression { return params.[2] }
}
steps {
echo 'Running tests...'
}
}
}The parameter name must be consistent in definition and usage. Here, RUN_TESTS is used in both places.
Fill all three blanks to define a choice parameter and print the selected option.
parameters {
choice(name: '[1]', choices: ['dev', '[2]', 'prod'], description: 'Select environment')
}
stages {
stage('Print Env') {
steps {
echo "Selected environment is: ${params.[3]"
}
}
}The choice parameter is named ENVIRONMENT, includes 'staging' as a choice, and is accessed as params.ENVIRONMENT.