Jenkinsfile syntax highlighting in Java project using Intellij Idea

笑着哭i 提交于 2019-12-02 17:22:29

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).

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:

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

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.

Another option is to use a shabang on top of the Jenkinsfile like this #!/usr/bin/env groovy. Also you can try out gdsl: https://st-g.de/2016/08/jenkins-pipeline-autocompletion-in-intellij but so far it doesn't support declarative pipelines: https://issues.jenkins-ci.org/browse/JENKINS-40127

Below is the feedback we've got from IntelliJ. We will follow up on this if we are able to provide a working solution.

Andrey Dernov, IntelliJ, Dec 14, 07:50 CET

Hello Georg, there is no special Editor intellisense support for editing Jenkinsfiles in IDE. You will need to write a custom language plugin for this.

Or you can consider implementing such support via writing Kotlin DSL. Some examples to start with.

Neil Millard

Looking at the source code, it looks like COMMENTS are not defined (they are commented out in the code)

The STEP_KEY is defined as: STEP_NAME="sh" | "parallel"

I'm not sure the plugin does much more and it hasn't been updated in 2 years.

Use sh like this and the error should go away (worked for me)...

steps {
    sh """
        echo 'Hello, World!'
    """
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!