0
0
Jenkinsdevops~10 mins

Pipeline linting and validation in Jenkins - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to run Jenkins pipeline linting using the CLI.

Jenkins
jenkins-cli.jar [1] < Jenkinsfile
Drag options to blanks, or click blank then click option'
Alint
Bvalidate
Crun
Dbuild
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'build' runs the pipeline instead of checking syntax.
Using 'validate' is not a valid Jenkins CLI command for linting.
2fill in blank
medium

Complete the Jenkinsfile snippet to validate the pipeline syntax before running.

Jenkins
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')
          }
        }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Acheck
Brun
Cbuild
Dlint
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'build' will try to run the pipeline, not lint it.
Using 'check' is not a valid Jenkins CLI command.
3fill in blank
hard

Fix the error in the Jenkinsfile validation step by completing the missing command.

Jenkins
stage('Validate') {
  steps {
    script {
      def status = sh(script: 'jenkins-cli.jar [1] < Jenkinsfile', returnStatus: true)
      if (status != 0) {
        error('Invalid pipeline syntax')
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Aexecute
Brun
Clint
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' or 'execute' tries to run the pipeline, not validate syntax.
Using 'start' is not a Jenkins CLI command.
4fill in blank
hard

Fill both blanks to create a Jenkins pipeline step that fails if the pipeline syntax is invalid.

Jenkins
def result = sh(script: 'jenkins-cli.jar [1] < Jenkinsfile', returnStatus: true)
if (result [2] 0) {
  error('Syntax error in pipeline')
}
Drag options to blanks, or click blank then click option'
Alint
B==
C!=
Dbuild
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'build' instead of 'lint' runs the pipeline.
Using '==' instead of '!=' will not catch errors correctly.
5fill in blank
hard

Fill all three blanks to create a Jenkins pipeline snippet that lints the Jenkinsfile, stores the status, and errors if invalid.

Jenkins
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')
          }
        }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Alint
B!=
Cerror
Dbuild
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'build' instead of 'lint' runs the pipeline.
Using '==' instead of '!=' misses errors.
Using 'error' as a string or missing parentheses causes syntax errors.