VSCode 和 Jenkinsfiles。我如何格式化它们?

Dav*_*est 11 visual-studio-code

我想在 VSCode 'Shift-Alt F' 中修复 Jenkinsfiles 中的格式给我“没有安装 'groovy' 文件的格式化程序”并弹出一个扩展侧边栏,没有相关的扩展来帮助进行格式化。

如何格式化我的文件。谢谢。我安装了“Jenkinsfile Support”和“cod-groovy”。仍然没有骰子。

谢谢。

Kal*_*ana 5

对于 Groovy 没有名为Format Document (ALT+SHIFT+F). 更多细节

但是有一个棘手的方法可以做到这一点,

  1. .groovy文件扩展名更改为.js.
  2. 之后,右键单击该文件并选择Format Document

希望这会帮助你。

  • @Subham 这个问题略有不同。Jenkinsfile 与普通的 Groovy 文件有一些共同点,但它们并不完全相同。 (4认同)

jul*_*con 5

您可以使用此扩展https://marketplace.visualstudio.com/items?itemName=ivory-lab.jenkinsfile-support称为 JenkinsFile 支持。

还可以使用此处定义的解决方法(使用files.associationsVSCode 的选项)为文件名中包含 Jenkinsfile 字符串的任何文件提供 linting https://github.com/sgwozdz/jenkinsfile-support/issues/62#issuecomment-829353453

    "files.associations": {
        "[Jj]enkinsfile*": "jenkinsfile"
    }
Run Code Online (Sandbox Code Playgroud)

如果您不想使用外部扩展,您可以在设置中使用 groovy Id(请记住,Groovy 与 Jenkinsfiles 不是一对一的)

    "files.associations": {
        "[Jj]enkinsfile*": "groovy"
    }
Run Code Online (Sandbox Code Playgroud)

  • 该插件似乎没有格式化 Jenkinsfile 的功能。 (17认同)