VSCode and Jenkinsfiles. How do I format them?

For Groovy There is no option called Format Document (ALT+SHIFT+F). More details

But there is an tricky method to do this,

  1. Change your .groovy file extension to .js.
  2. After that right click on the file and select Format Document

Hope this will help you.


You can use this extension https://marketplace.visualstudio.com/items?itemName=ivory-lab.jenkinsfile-support called JenkinsFile Support.

And also use the workaround defined here (using the files.associations option of VSCode) to give linting for any file with the Jenkinsfile string in the filename https://github.com/sgwozdz/jenkinsfile-support/issues/62#issuecomment-829353453

    "files.associations": {
        "[Jj]enkinsfile*": "jenkinsfile"
    }

If you don't want to use external extensions, you can use the groovy Id in your settings (just remember, Groovy is not one to one to Jenkinsfiles)

    "files.associations": {
        "[Jj]enkinsfile*": "groovy"
    }