-
Notifications
You must be signed in to change notification settings - Fork 258
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.
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)
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 {
^
ssh -p 8675 localhost declarative-linter < src/test/resources/basicWhen.groovy
Jenkinsfile successfully validated.
Documentation
- Getting Started
- Running multiple steps
- Controlling your build environment
- Environment variables
- Reporting test results and storing artifacts
- Notifications
- Deployment and credentials
- Parallelism
- Triggering runs
- Parametrized pipelines
- Pipeline options and log rotation
- Jenkinsfile validation from the CLI
- Advanced pipeline authoring
- Syntax reference
- Version history and changes
Examples