Complete the code for the build stage.
pipeline {
agent any
stages {
stage('Build') {
steps {
sh '[1]'
}
}
}
}The sh step runs shell commands. mvn clean install is a typical command used in the build stage.
Complete the code to check the pipeline syntax using Jenkins CLI.
java -jar jenkins-cli.jar -s http://localhost:8080 [1] < Jenkinsfile
build which trigger builds instead of validation.The Jenkins CLI command declarative-linter checks the syntax of a declarative pipeline.
Fix the error in the pipeline syntax validation command.
java -jar jenkins-cli.jar -s http://localhost:8080 [1] < Jenkinsfile
build which triggers a build instead of validation.validate.The correct Jenkins CLI command to validate pipeline syntax is declarative-linter. Other commands either do not exist or perform different actions.
Fill both blanks to create a Jenkins pipeline stage that validates the pipeline syntax before running.
stage('Validate') { steps { script { def result = sh(script: '[1]', returnStatus: true) if (result [2] 0) { error('Pipeline syntax validation failed') } } } }
The shell command runs the Jenkins CLI declarative-linter to check syntax. The returnStatus: true captures the exit code. If the result is not zero (!= 0), it means validation failed, so the pipeline errors out.
Fill all three blanks to create a Jenkins pipeline snippet that validates the pipeline syntax and aborts if invalid.
pipeline {
agent any
stages {
stage('Validate Pipeline') {
steps {
script {
def status = sh(script: '[1]', returnStatus: true)
if (status [2] 0) {
[3]('Pipeline syntax is invalid, aborting build')
}
}
}
}
}
}The shell command runs the Jenkins CLI declarative-linter to validate the pipeline. If the status is not zero (!= 0), it means validation failed, so the error step aborts the build with a message.