Complete the code to trigger a Jenkins build manually.
pipeline {
agent any
stages {
stage('Build') {
steps {
[1] 'echo Building project'
}
}
}
}The sh step runs shell commands in Jenkins pipelines. Here, it runs the echo command.
Complete the code to define an environment variable in Jenkins pipeline.
pipeline {
agent any
environment {
GREETING = [1]
}
stages {
stage('Example') {
steps {
sh 'echo $GREETING'
}
}
}
}Environment variable values must be strings. Use quotes like 'Hello World' to define the value.
Fix the error in the Jenkins pipeline to run a shell command.
pipeline {
agent any
stages {
stage('Test') {
steps {
[1] 'echo Testing'
}
}
}
}The correct Jenkins pipeline step to run shell commands is sh. Other options cause errors.
Fill both blanks to create a Jenkins pipeline stage that runs a shell command and sets a variable.
pipeline {
agent any
stages {
stage('Build') {
steps {
script {
[1] = [2] 'echo Hello'
}
}
}
}
}Use def to declare a variable and sh to run the shell command in Jenkins scripted pipeline.
Fill all three blanks to create a Jenkins pipeline that defines a map with keys and values filtered by a condition.
pipeline {
agent any
stages {
stage('Filter') {
steps {
script {
def data = [a: 1, b: 2, c: 3, d: 4]
def filtered = data.findAll { [1], [2], [3] }
echo "Filtered: ${filtered}"
}
}
}
}
}In Jenkins scripted pipeline Groovy, findAll uses a closure. The correct syntax is { k, v -> v > 2 }. Here, blanks fill parts of the closure.