Complete the code to run Jenkins pipeline linting using the CLI.
jenkins-cli.jar [1] < JenkinsfileThe lint command checks the Jenkinsfile syntax without running it.
Complete the Jenkinsfile snippet to validate the pipeline syntax before running.
pipeline {
agent any
stages {
stage('Lint') {
steps {
script {
def result = sh(script: 'jenkins-cli.jar [1] < Jenkinsfile', returnStatus: true)
if (result != 0) {
error('Pipeline syntax error detected')
}
}
}
}
}
}The lint command checks the syntax of the Jenkinsfile and returns a status code.
Fix the error in the Jenkinsfile validation step by completing the missing command.
stage('Validate') { steps { script { def status = sh(script: 'jenkins-cli.jar [1] < Jenkinsfile', returnStatus: true) if (status != 0) { error('Invalid pipeline syntax') } } } }
The lint command is used to check the Jenkinsfile syntax and returns a status code.
Fill both blanks to create a Jenkins pipeline step that fails if the pipeline syntax is invalid.
def result = sh(script: 'jenkins-cli.jar [1] < Jenkinsfile', returnStatus: true) if (result [2] 0) { error('Syntax error in pipeline') }
The lint command checks syntax. The condition uses != to detect errors (non-zero status).
Fill all three blanks to create a Jenkins pipeline snippet that lints the Jenkinsfile, stores the status, and errors if invalid.
pipeline {
agent any
stages {
stage('Lint') {
steps {
script {
def status = sh(script: 'jenkins-cli.jar [1] < Jenkinsfile', returnStatus: true)
if (status [2] 0) {
[3]('Pipeline syntax error detected')
}
}
}
}
}
}The lint command checks syntax. The condition uses != to detect errors. The error step stops the pipeline with a message.