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.

My favorite feature of this validation is that it also checks semantical issues like running a step block outside of a stage block.

And it finds those issues immediately!
No more running until it fails for me!

Leave a Reply

Your email address will not be published.

Required fields are marked *

Your avatar