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

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

问题描述

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

We already tried the approaches as listed below:

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

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?

如果在idea中没有办法让Jenkinsfile的语法高亮和自动补全,还有什么其他的编辑器会有所帮助?

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

请注意:

  • 我们正在处理 java 项目,而不是 groovy 项目.

  • we are working with java projects, not groovy projects.

我们已经尝试过插件https://github.com/oliverlockwood/jenkinsfile-idea-plugin.当插件被激活时,Jenkinsfile 被识别为这样,但我们收到一条错误消息,而不是语法突出显示,请参见下文.

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 将 pipelinep 高亮显示为错误.错误信息如下:

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

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

感谢您的帮助!

推荐答案

我们终于找到了一个对我们有用的解决方案,并为 Idea 中一个普通 Java 项目中存在的 Jenkinsfile 提供语法突出显示和代码完成.解决方案取自此处此处(来自其他个人实验/研究)

At long last we found a solution that works for us and provides syntax highlighting and code completion for the Jenkinsfile present in an otherwise normal Java project in Idea. The solution is taken from here, here (and from additional personal experiments / research)

  1. Groovy 页面下载 Groovy SDK(如果您还没有这样做的话)a> 并在您的 Java 项目中配置它.如需这方面的帮助,请参阅此处

从您的 Jenkins 实例下载管道 GDSL 文件,该文件应该可以在 https 等链接下找到://yourJenkinsInstance.tld/pipeline-syntax/gdsl,并将其添加到您的Java项目的类路径中.例如.通过创建一个新文件夹 src/main/jenkins,将管道 gdsl 文件放在那里并将该文件夹标记为 IntelliJ Idea 中的源根目录

Download the pipeline GDSL file from your Jenkins instance which should be available under a link like https://yourJenkinsInstance.tld/pipeline-syntax/gdsl, and add it to the classpath of your Java project. E.g. by creating a new folder src/main/jenkins, putting the pipeline gdsl file there and marking the folder as source root in IntelliJ Idea

添加Jenkinsfile"作为 groovy 文件的有效文件名模式,如此处

Add "Jenkinsfile" as a valid file name pattern for groovy files as described here

为避免出现'node' cannot be applied to '(groovy.lang.Closure<java.lang.Object>)的错误信息,可以在顶部添加这一行你的詹金斯档案:

To avoid the error message 'node' cannot be applied to '(groovy.lang.Closure<java.lang.Object>), you can add this line at the top of your Jenkinsfile:

//不检查 GroovyAssignabilityCheck

// noinspection GroovyAssignabilityCheck

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

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