Skip to content

Validating (or linting) a Declarative Jenkinsfile from the command line

Andrew Bayer edited this page Dec 13, 2016 · 3 revisions

You can validate, or lint, your Declarative Jenkinsfile from the command line before running a build, using a Jenkins CLI command. See the Jenkins wiki for more information on the Jenkins CLI, but note that we recommend using the SSH interface for running the linter.

You can also use curl to post the Jenkinsfile directly, but again, we recommend the SSH approach.

How to use

ssh -p [sshd port on master] [Jenkins master hostname] declarative-linter < Jenkinsfile

or

curl -X POST -H `curl 'JENKINS_URL/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'` -F 'jenkinsfile="@Jenkinsfile"' JENKINS_URL/pipeline-model-converter/validate

(the crumbIssuer bit is needed if your Jenkins master has CRSF enabled, as it should)

Example output

Invalid

ssh -p 8675 localhost declarative-linter < src/test/resources/errors/emptyAgent.groovy
Errors encountered validating Jenkinsfile:
WorkflowScript: 25: Not a valid section definition: 'agent'. Some extra configuration is required. @ line 25, column 1.
   pipeline {
   ^

WorkflowScript: 25: Missing required section 'agent' @ line 25, column 1.
   pipeline {
   ^

Valid

ssh -p 8675 localhost declarative-linter < src/test/resources/basicWhen.groovy
Jenkinsfile successfully validated.

Clone this wiki locally