Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkinsfile syntax highlighting in PyCharm Idea

I've been looking an so far have been unable to find any way of enabling syntax highlighting for jenkinsfile in PyCharm. Does anyone know of a method to do this? I am specifically using scripted pipeline.

like image 368
Anthony Martin Avatar asked Jul 01 '18 16:07

Anthony Martin


People also ask

What file type is Jenkinsfile?

As discussed in the Defining a Pipeline in SCM, a Jenkinsfile is a text file that contains the definition of a Jenkins Pipeline and is checked into source control. Consider the following Pipeline which implements a basic three-stage continuous delivery pipeline.

How do you use GDSL?

gdsl” anywhere in the classpath. For an example go to any package in your project src, and right click on it from within the IDE and select new>Groovy Script. Now a dialog will appear and then select “GroovyDSL Script” in the “kind” parameter. Now you have the script file and you can start coding GDSL in here.

How does IntelliJ integrate with Jenkins?

Open IntelliJ IDEA. Click on Import Project, and in the popup, choose the directory where Jenkins had been cloned. Select 'Create project from existing sources', and click on Next. Click on Finish.


2 Answers

The following filetype xml will highlight Jenkinsfile syntax in PyCharm

JFHighlight

create a new Jenkinsfile.xml, copy the following xml:

<filetype binary="false" description="Jenkinsfile support" name="Jenkinsfile">   <highlighting>     <options>       <option name="LINE_COMMENT" value="//" />       <option name="COMMENT_START" value="/*" />       <option name="COMMENT_END" value="*/" />       <option name="HEX_PREFIX" value="" />       <option name="NUM_POSTFIXES" value="" />       <option name="HAS_BRACES" value="true" />       <option name="HAS_BRACKETS" value="true" />       <option name="HAS_PARENS" value="true" />       <option name="HAS_STRING_ESCAPES" value="true" />       <option name="LINE_COMMENT_AT_START" value="true" />     </options>     <keywords keywords="def;else;if;import;print;return" ignore_case="true" />     <keywords2 keywords="node" />     <keywords3 keywords="field;library;stage;string" />     <keywords4 keywords="try;catch;finally" />   </highlighting>   <extensionMap>     <mapping pattern="Jenkinsfile" />   </extensionMap> </filetype> 

and place it under

macOS

~/Library/Preferences/PyCharmXX/filetypes 

Linux copy to

/.PyCharmXX/config/filetypes 

Win copy to

<User home>\.PyCharmXX\config\filetypes 

https://github.com/galCohen88/pycharm-jenkinsfile

like image 152
gCoh Avatar answered Sep 18 '22 12:09

gCoh


~~Unfortunately, Pycharm does not currently support Groovy/Jenkinsfile syntax highlighting.~~

UPDATE: Please see the other answers on this thread to check if groovy support is discovered or added for PyCharm.

While this does not officially answer your question it does provide a workaround for those who are interested.

Install IntelliJ IDEA, the community edition can be downloaded free from intelliJ

Once installed, open File-->Settings-->Editor-->File Types-->Groovy and you can associate Jenkinsfile with the Groovy syntax by adding 'Jenkinsfile*' to the Groovy 'Registered patterns':

enter image description here

A word to the wise: Don't open the Jenkinsfile directly in your Pycharm project with IDEA. It will start writing to the '.idea' folder and cause conflicts with the pyCharm IDE. I like to symlink/softlink my Jenkinsfile into a subdirectory of a folder called 'jenkinsfiles'. So if I have a project called ProjectA I symlink the Jenkins file to ..path../jenkinsfiles/ProjectA/Jenkinsfile. I then open ..path../jenkinsfiles/ in IDEA and can manage all the Jenkinsfiles for all my projects from there.

UPDATE: lately I have been enjoying the free https://code.visualstudio.com/ which has a groovy plugin https://marketplace.visualstudio.com/items?itemName=marlon407.code-groovy.

like image 29
Lance Avatar answered Sep 20 '22 12:09

Lance