我们已经尝试了以下方法:
https://github.com/oliverlockwood/jenkinsfile-idea-plugin
https://st-g.de/2016/08/jenkins-pipeline-autocompletion-in-intellij
在多天的时间里在网上搜索了多个小时后,我们仍然没有找到有关此问题的有用资源。因此,在这里提出一个新问题似乎很有意义。
我们正在以IntelliJ理念开发Java项目,并希望将我们的构建与Jenkins集成。在Idea中创建Jenkinsfile时,不会突出显示语法或自动完成。由于我们是詹金斯的新手,因此这些功能对我们真的很有用。我们如何才能使Idea更好地支持Jenkinsfiles?
如果没有办法让Jenkinsfile语法高亮显示和自动完成,那么还有哪些其他编辑器会有所帮助?
请注意:
we are working with java projects, not groovy projects.
We've already tried the plugin https://github.com/oliverlockwood/jenkinsfile-idea-plugin. When the plugin is activated, the Jenkinsfile is recognized as such, but instead of syntax highlighting we get an error message, please see below.
pipeline {
agent { docker 'maven:3.3.3' }
stages {
stage('build') {
steps {
sh 'echo Hello, World!'
}
}
}
}
Idea highlights the 'p' of 'pipeline' as error. The error message reads:
JenkinsTokenType.COMMENT, JenkinsTokenType.CRLF or JenkinsTokenType.STEP_KEY expected, got 'p'
谢谢你的帮助!
最佳答案
如果希望IDEA将Jenkinsfile识别为Groovy文件,则可以将字符串“ Jenkinsfile”添加为Groovy文件的有效文件名模式(通常包含文件结尾)。支持“开箱即用”,不需要任何其他插件(“ Groovy”插件除外,但它已经是IDEA的一部分)。
为此,请转到设置菜单,打开“编辑器”项,然后打开“文件类型”。现在,在上方列表中选择“ Groovy”并添加“ Jenkinsfile”。如果您希望在Jenkinsfile结尾的可选文件方面更加灵活,也可以使用“ Jenkinsfile *”之类的正则表达式。
现在,设置应如下所示:
您的示例现在在IDEA(具有Dracula主题)中如下所示:
因此,据我所知,IDEA现在提供了语法突出显示和自动完成功能。它在编写时会建议现有的函数/方法名称,但我不是Groovy开发人员,因此我无法确定是否缺少一些建议。