Validate Jenkinfiles in VSCode
Jenkins pipelines are cool but writing Jenkinsfiles is a frustrating experience, especially if you are not familiar with Groovy. Testing them can be tedious, too. And to add insult to injury, editor support is not quite good.
However, there are ways to make Jenkinsfile development less painful. One quality of life improvement is being able to validate a Jenkinsfile while developing it, directly in VSCode.
To add linter-like support for Jenkinsfiles in VSCode, take a look at Jenkins Pipeline Linter Connector extension (view).
It’s a wrapper of Jenkins’ REST API for linting Jenkinsfiles that makes much more convenient checking whether currently opened file is a valid Jenkinsfile or not.
To set it up, add proper values to the following keys in your VSCode settings.json
(> Open Settings (JSON)
in Command Palette). I didn’t need to set up any other key to validate my Jenkinsfiles in my Jenkins setup:
jenkins.pipeline.linter.connector.user
– your Jenkins username. In my installation it was visible in the top navigation bar.jenkins.pipeline.linter.connector.pass
– a Jenkins API token (Jenkins » Click on your username » Configure » API Token).jenkins.pipeline.linter.connector.url
– the URL to your Jenkins instance lint endpoint. In my installation it was<ROOT_URL>/pipeline-model-converter/validate
.
After settings are in place you’ll be able to validate any Jenkinsfile using > Validate Jenkisfile
command.
No replies on “Validate Jenkinfiles in VSCode”