Complete the code to define a Jenkins job that runs a shell command.
pipeline {
agent any
stages {
stage('Build') {
steps {
[1] 'echo Hello, Jenkins!'
}
}
}
}The sh step runs shell commands in Jenkins pipelines. It is the correct way to execute shell commands.
Complete the code to trigger a Jenkins job after another job finishes.
post {
success {
[1] 'DeployJob'
}
}The build step triggers another Jenkins job from a pipeline.
Fix the error in the Jenkins pipeline code to archive artifacts correctly.
steps {
[1] artifacts: '**/*.jar', fingerprint: true
}The correct step to archive build artifacts in Jenkins is archiveArtifacts.
Fill both blanks to create a Jenkins pipeline stage that runs only on the master branch.
stage('Deploy') { when { expression { BRANCH_NAME.[1]('master') } } steps { [2] 'deploy.sh' } }
The when condition uses equals to check the branch name. The sh step runs the shell script.
Fill all three blanks to define a Jenkins pipeline that checks out code, builds, and archives artifacts.
pipeline {
agent any
stages {
stage('Checkout') {
steps {
[1] scm
}
}
stage('Build') {
steps {
[2] './build.sh'
}
}
stage('Archive') {
steps {
[3] artifacts: '**/target/*.jar'
}
}
}
}checkout pulls the source code, sh runs the build script, and archiveArtifacts saves the build outputs.