Jenkins Pipeline plugin: code completion in IntelliJ

The Pipeline plugin (formerly Workflow plugin) for Jenkins revolutionises working with Jenkins by allowing for the creation of build jobs as code. As a result, build pipelines can be put under version control, become reusable,testable and more easily readable, among other things, as something “put together with mouse clicks”.

In order to learn the Jenkins Pipeline domain specific language (DSL) in an exploratory way as well as to work with it more efficiently later, code completion is very helpful. This article demonstrates how this can be realised with IntelliJ IDEA in just a few steps.

When using the Pipeline plugin, it is a convention to describe the Pipeline in a file called Jenkinsfile. Anyone who sticks to this is already halfway to code completion by IDEA – the Jenkinsfile filename is already associated with the Groovy programming language. As a result, you already have code completion for all Groovy language constructs.

However, this doesn’t help at all when it comes to the Pipeline DSL. The language constructs available here depend on which plugins are installed in the instance of Jenkins being used. Consequently, this information must also be obtained from there. For this, the Pipeline plugin provides a description in the form of a Groovy DSL script (GDSL) file. This can be downloaded from

https://<Jenkins>/job/<Job Name>/pipeline-syntax/gdsl

If, for example, Jenkins runs under localhost and a job myproject is set up, the URL for the GDSL file is

https://localhost/job/myproject/pipeline-syntax/gdsl

In order for this to be read by IntelliJ, it must be saved in a source folder with the suffix .gdsl, for example under src/main/groovy/jenkins.gdsl. Depending on the folder and project, this must still be designated as a sources folder under File | Project Structure | Modules. Then, the following should be possible in Jenkinsfile:

Tested with IntelliJ 2017.1.2 and Jenkins ver. 2.46.2.

Share this article

Kommentare

Johannes Schnatterer
Solution Architect
With a special focus on quality, open source enthusiasm, a touch of pedantry and Boy Scout Rule under his belt, he is trying to make the world of IT a little better every day.