使用Intellij Idea在Java项目中突出显示Jenkinsfile语法 [英] Jenkinsfile syntax highlighting in Java project using Intellij Idea

查看:845
本文介绍了使用Intellij Idea在Java项目中突出显示Jenkinsfile语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经尝试了以下方法:

We already tried the approaches as listed below:

  • https://github.com/oliverlockwood/jenkinsfile-idea-plugin
  • https://st-g.de/2016/08/jenkins-pipeline-autocompletion-in-intellij

经过数天在网上搜索了多个小时之后,我们仍然没有找到有关此事的有用资源.因此,在这里提出一个新问题似乎很有意义.

After having searched the web for many hours on multiple days, we still haven't found a helpful resource on this matter. Thus, it appears to make sense to ask a new question here.

我们正在以IntelliJ想法开发Java项目,并希望将我们的构建与Jenkins集成.在Idea中创建Jenkinsfile时,不会突出显示语法或自动完成.由于我们是Jenkins的新手,因此这些功能对我们真的很有用.我们如何才能使Idea更好地支持Jenkinsfiles?

We are developing our Java projects in IntelliJ idea and want to integrate our builds with Jenkins. When we create a Jenkinsfile in Idea, we do not get syntax highlighting or auto completion. Since we are new to Jenkins, those features would be really useful to us. How can we make Idea be more supportive with Jenkinsfiles?

如果没有办法让Jenkinsfile语法高亮显示和自动完成,那么还有哪些其他编辑器会有所帮助?

If there is no way to get syntax highlighting and auto completion for a Jenkinsfile in idea, what other editors would be helpful?

请注意:

  • 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!'
        }
    }
  }
}

想法将管道"的"p"突出显示为错误.错误消息显示为:

Idea highlights the 'p' of 'pipeline' as error. The error message reads:

JenkinsTokenType.COMMENT,JenkinsTokenType.CRLF或JenkinsTokenType.STEP_KEY预期为'p'

JenkinsTokenType.COMMENT, JenkinsTokenType.CRLF or JenkinsTokenType.STEP_KEY expected, got 'p'

感谢您的帮助!

推荐答案

如果您希望IDEA将Jenkinsfile识别为Groovy文件,则可以将字符串"Jenkinsfile"添加为有效的文件名模式(通常包含文件结尾) )用于Groovy文件.无需任何其他插件即可开箱即用"支持("Groovy"插件除外,但该插件已成为IDEA的一部分).

If you want IDEA to recognize a Jenkinsfile as a Groovy file, then you can add the String "Jenkinsfile" as a valid file name pattern (normally contains file endings) for Groovy files. This is supported "out of the box" without requiring any additional Plugin (except the "Groovy" Plugin, but that is already part of IDEA).

要执行此操作,请转到设置菜单,打开编辑器"项,然后打开文件类型".现在,在上方列表中选择"Groovy"并添加"Jenkinsfile".如果要在Jenkinsfile结尾的可选文件方面更加灵活,也可以使用"Jenkinsfile *"之类的正则表达式.
现在,设置应如下所示:

To do that go to the settings menu, open the "Editor" item and then "File Types". Now select "Groovy" in the upper list and add "Jenkinsfile". You can also use a regex like "Jenkinsfile*" if you want to be more flexible regarding an optional file ending for the Jenkinsfile.
The setting should now look like this:

您的示例现在在IDEA(具有Dracula主题)中如下所示:

Your example now looks like this in IDEA (with the Dracula theme):

据我所知,IDEA现在提供了语法高亮显示和自动完成功能.它会在编写时建议现有的函数/方法名称,但我不是Groovy开发人员,因此我无法确定是否缺少一些建议.

So IDEA now provides syntax highlighting and auto completion as far as I can tell. It suggests existing function/method names while writing, but I'm not a Groovy developer, thus I can't tell if some suggestions are missing.

这篇关于使用Intellij Idea在Java项目中突出显示Jenkinsfile语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆