Complete the code to start a Jenkins job from the command line.
java -jar jenkins-cli.jar -s http://localhost:8080 [1] MyJob
The correct command to start a Jenkins job using CLI is build.
Complete the Jenkinsfile snippet to define a pipeline stage.
pipeline {
agent any
stages {
stage('[1]') {
steps {
echo 'Hello, Jenkins!'
}
}
}
}The stage name here is 'Build' to represent the build step in the pipeline.
Fix the error in the Jenkinsfile to correctly declare an environment variable.
pipeline {
agent any
environment {
GREETING = '[1]'
}
stages {
stage('Example') {
steps {
echo "${GREETING}, Jenkins!"
}
}
}
}Environment variables in Jenkinsfile need to be assigned string values with quotes, single or double. Single quotes are common.
Fill both blanks to create a Jenkins pipeline that runs a shell command only on the master branch.
pipeline {
agent any
stages {
stage('Build') {
when {
branch [1] '[2]'
}
steps {
sh 'echo Building on master branch'
}
}
}
}The when condition uses equals to check if the branch is 'master'.
Fill all three blanks to define a Jenkins pipeline with parameters and a conditional step.
pipeline {
agent any
parameters {
string(name: '[1]', defaultValue: 'World', description: 'Who to greet')
}
stages {
stage('Greet') {
steps {
script {
if (params.[2] == '[3]') {
echo "Hello, ${params.NAME}!"
}
}
}
}
}
}The parameter is named 'NAME', and the script checks if params.NAME equals 'World' to print the greeting.