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.
-
Maybe you could associate it with [Groovy](https://jenkins.io/doc/book/pipeline/jenkinsfile/#advanced-scripted-pipeline). – Peter Wood Jul 01 '18 at 16:13
-
4Tried that but couldn't find a method to get Groovy syntax in PyCharm specifically. – Anthony Martin Jul 01 '18 at 16:29
5 Answers
The following filetype xml will highlight Jenkinsfile syntax in PyCharm
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

- 2,719
- 1
- 22
- 46
-
-
-
just notice that for windows I didn't add the \filetypes folder in the answer. – gCoh Jul 03 '19 at 07:41
-
For some weird reason when I put the file in the right folder PyCharm didn't recognise it, but when I created the file type manually within PyCharm the .xml file was created in the same path (and also looked the same) – kaki gadol Jul 16 '19 at 08:16
-
-
figured it out, for some reason after few pycharm restarts it worked.. maybe I did something wrong with my file.. nvm- now it works. Thanks! – kaki gadol Jul 17 '19 at 13:06
-
make sure to save xml above into a file named: 'Jenkinsfile.xml' and restart pycharm (make sure no open pycharm windows are forgotten) – oneklc Aug 15 '19 at 05:38
-
This was helpful for me to add this association manually in Pycharm and don't have to worry about copying files around. Look at my answer with a screenshot for easy reference below. – Rockoder Mar 13 '20 at 13:27
-
4Note that for macOS with version 2020.1+ the directory changed to something like: `~/Library/Application Support/JetBrains/PyCharmCE2020.2/filetypes` – rerx Nov 25 '20 at 11:40
-
-
1This just worked perfectly for me using PyCharm 2018.2.5. using the Windows instructions at the bottom of the answer. Had to create the folder and then add the file as instructed. Restarted PyCharm and now it works. – TomServo Apr 07 '21 at 17:37
-
I created the file type **[directly in the PyCharm GUI](https://www.jetbrains.com/help/pycharm/creating-and-registering-file-types.html#create-new-file-type)** using the helpful values from this answer. Each option name has a corresponding field in the GUI. Then I associated the file type with `*Jenkinsfile*`. – Scott H Aug 12 '23 at 00:11
~~Unfortunately, Pycharm does not currently support Groovy/Jenkinsfile syntax highlighting.~~
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':
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.
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.
-
This doesn't answer the question and instead tells viewers to download another IDE. It may be related, and it may work, but it's not a solution to add syntax highlighting to PyCharm. – ingyhere Jun 04 '20 at 16:37
-
A fact to which I concede in this answer. At that stage, there were no answers to this question for some time. I've since updated to direct readers to more appropriate answers. – Lance Jun 04 '20 at 18:23
It's possible. We can add groovy TextMate bundle to PyCharm. Unfortunately PR for Jenkinsfile
support waiting for a long time, so we need to do some changes in packet manually.
- Download and unpack https://github.com/textmate/groovy.tmbundle/archive/master.zip
- open
path_to_unpacked_package/Groovy.tmLanguage
file in editor and add<string>Jenkinsfile</string>
after line<string>gvy</string>
- Open PyCharm->Settings->TextMate Bundles and add modified
groovy.tmbundle
Based on this answer and tested on PyCharm 2019.1.2 Pro
P.S. As alternative one can use this fork without any modifications
P.P.S. from @jeff-welling comment: If you have no TextMate Bundles
in setup, then follow this instruction to install it
Pycharm 2019.2 changelog: PyCharm will now highlight the syntax of Windows .bat files, C#, C++, Groovy, Lua, Makefiles, and more

- 14,745
- 4
- 31
- 54
-
1If, like me, you are confused about why you can't see TextMate Bundles in your settings, it's a plugin that you need to install first. Details here: https://blog.jetbrains.com/pycharm/2014/12/feature-spotlight-textmate-bundles-in-pycharm/ – Jeff Welling Jun 06 '19 at 16:32
-
Note it also useful for Jenkins pipeline syntax. just copy the pipeline code and save it as groovy – arielma Nov 25 '19 at 20:26
-
1The `PR` referenced above is on a [repository without commits since 2014](https://github.com/textmate/groovy.tmbundle/commits/master). Perhaps the software is finished, and it might well work, but obviously isn't maintained. `TextMate` is apparently renamed `MacroMates` now. Anyway, these bundles are based on plugin architecture for a Mac OS X text editor, **TextMate**. I'm looking for something more IntelliJ native. – ingyhere Jun 03 '20 at 21:41
-
[**Files supported via TextMate bundles** is missing in PyCharm 2020.1.3 Community Edition](https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000062010-Files-supported-via-TextMate-bundles-missing-?page=1#community_comment_360001793100) – Abhijeet Jul 20 '20 at 04:47

- 746
- 2
- 11
- 22
-
1It's "Jenk**sins**" in the Recognized File Types list. I'm not sure if that was a Freudian slip or on purpose, but it's real. – ingyhere Jun 04 '20 at 16:42
-
1This works but only gives you basic text highlights. You do not get features such as auto-indent and other code related IDE enhancements – Joe Haddad Feb 10 '21 at 17:29
You can't associate Jenkinsfile
with Groovy in PyCharm, but you can associate them with Java. Not perfect, but the syntax is similar enough to be useful for simple files.
To do that (in PyCharm 2018.3):
PyCharm → Preferences → Editor → File Types → Select "Java" under "Recognized File Types" → Click the + → Type "Jenkinsfile"

- 5,141
- 5
- 38
- 59

- 2,125
- 1
- 11
- 19
-
Easier and probably just as good as the answer to add a linited, custom filetype xml. – ingyhere Jun 04 '20 at 16:40
-
4