0
0
Jenkinsdevops~5 mins

Pipeline validation in Jenkins - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you create a Jenkins pipeline, you want to make sure it works before running it fully. Pipeline validation checks your pipeline script for errors so you can fix them early and avoid broken builds.
When you write a new Jenkins pipeline script and want to check it for mistakes before running.
When you update an existing pipeline and want to confirm the changes are correct.
When you want to catch syntax errors or missing steps in your pipeline script.
When you want to save time by validating the pipeline without triggering a full build.
When you want to ensure your pipeline script follows Jenkins syntax rules.
Commands
This command uses Jenkins CLI to validate the Jenkinsfile syntax without running the pipeline. It helps catch errors early.
Terminal
java -jar jenkins-cli.jar -s http://localhost:8080 declarative-linter < Jenkinsfile
Expected OutputExpected
No errors found
-s - Specifies the Jenkins server URL
Alternative command to run the Jenkins pipeline syntax check using the Jenkins CLI jar file.
Terminal
java -jar jenkins-cli.jar -s http://localhost:8080 declarative-linter < Jenkinsfile
Expected OutputExpected
No errors found
-s - Specifies the Jenkins server URL
This command sends the Jenkinsfile to Jenkins REST API to validate the pipeline syntax.
Terminal
curl -X POST -F 'jenkinsfile=<@Jenkinsfile' http://localhost:8080/pipeline-model-converter/validate
Expected OutputExpected
{"status":"ok","message":"Pipeline syntax is valid"}
Key Concept

If you remember nothing else from this pattern, remember: validating your Jenkins pipeline script before running saves time and prevents build failures.

Common Mistakes
Running the pipeline without validating the Jenkinsfile first
This can cause the build to fail and waste time fixing errors after starting the job.
Always validate the Jenkinsfile syntax using Jenkins CLI or REST API before running the pipeline.
Using an incorrect Jenkins server URL in the CLI command
The validation command will fail to connect and not check the pipeline.
Ensure the Jenkins server URL is correct and accessible when running validation commands.
Not redirecting the Jenkinsfile content properly to the CLI command
The CLI will not receive the pipeline script and cannot validate it.
Use input redirection like '< Jenkinsfile' to pass the pipeline script to the validation command.
Summary
Use Jenkins CLI or REST API to validate pipeline scripts before running.
Validation catches syntax errors early and prevents build failures.
Always specify the correct Jenkins server URL and pass the Jenkinsfile content properly.