0
0
Jenkinsdevops~5 mins

Pipeline linting and validation in Jenkins - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you write Jenkins pipelines, small mistakes can stop your automation. Pipeline linting and validation help catch errors early by checking your pipeline code before running it.
When you want to check your Jenkins pipeline script for errors before running it.
When you want to ensure your pipeline syntax follows Jenkins rules.
When you want to avoid pipeline failures caused by typos or missing steps.
When you want to automate pipeline checks in your development workflow.
When you want to share pipeline code with your team and keep it error-free.
Commands
This command sends your Jenkinsfile to the Jenkins server to check for syntax errors and validate the pipeline script before running it.
Terminal
java -jar jenkins-cli.jar -s http://localhost:8080/ declarative-linter < Jenkinsfile
Expected OutputExpected
{ "status": "ok", "message": "Pipeline script is valid" }
-s - Specifies the Jenkins server URL
This command checks an invalid Jenkinsfile and shows the error message explaining what is wrong in the pipeline script.
Terminal
java -jar jenkins-cli.jar -s http://localhost:8080/ declarative-linter < invalid-Jenkinsfile
Expected OutputExpected
{ "status": "error", "message": "Expected a step to be defined inside stage 'Build'" }
-s - Specifies the Jenkins server URL
Key Concept

If you remember nothing else from this pattern, remember: always validate your Jenkins pipeline code before running to catch errors early and save time.

Common Mistakes
Running pipeline without linting or validation
This causes pipeline failures that could have been caught early, wasting time and resources.
Always run the declarative-linter command on your Jenkinsfile before executing the pipeline.
Using the wrong Jenkins server URL or missing authentication
The linting command will fail to connect and cannot validate the pipeline script.
Ensure the Jenkins server URL is correct and you have proper access rights before running the lint command.
Summary
Use the Jenkins CLI declarative-linter command to check pipeline syntax before running.
Linting helps catch errors early and prevents pipeline failures.
Always verify the Jenkins server URL and access when running lint commands.