Complete the code to start a scripted Jenkins pipeline.
node {
stage('Build') {
[1] 'echo Building...'
}
}In scripted pipelines, sh runs shell commands inside the node block.
Complete the code to define a variable in scripted pipeline.
node {
def message = [1]
echo message
}Strings in Groovy (used by scripted pipelines) should be in quotes. Single quotes work well for simple strings.
Fix the error in the scripted pipeline to run a shell command.
node {
stage('Test') {
[1] 'echo Testing...'
}
}The sh step runs shell commands directly in scripted pipelines. Using steps.sh causes an error here.
Fill both blanks to create a scripted pipeline with a conditional stage.
node {
if (env.BRANCH_NAME == [1]) {
stage([2]) {
sh 'echo Deploying...'
}
}
}Branch names are strings and need quotes. Stage names also need quotes in scripted pipelines.
Fill all three blanks to define a scripted pipeline with a loop and shell command.
node {
for (int i = 0; i < [1]; i++) {
stage([2]) {
sh [3]
}
}
}The loop runs 5 times. Stage name is a string. Shell command is a string concatenating iteration number.