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.
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.
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.
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.
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
https://github.com/galCohen88/pycharm-jenkinsfile
~~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':
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With