IntelliJ Setup for Jenkins Core Development

This article is a walk-through guide on how to setup IntelliJ IDEA to develop and debug Jenkins core.

Index:

  1. Installation and Cloning

  2. Setting up IntelliJ IDEA

  3. Building Jenkins

  4. Debugging

1. Installation and Cloning

Install IntelliJ from here. Fork Jenkins core source code from here. Clone the forked repository to your machine. In this tutorial, IntelliJ IDEA Version 2019.3.1 has been used.

2. Setting up IntelliJ IDEA

Open IntelliJ IDEA.

setup1

Click on Import Project, and in the popup, choose the directory where Jenkins had been cloned.

setup2

Select ‘Create project from existing sources’, and click on Next.

setup3

Click on Next

setup4

Click on Next

setup5

Click on Next

setup6

Click on Finish. IntelliJ should be ready like below.

setup7

3. Building Jenkins

Now we want to build Jenkins. Run the following: (This will prepare the jenkins.war file without running tests)

mvn -am -pl war,bom -DskipTests -Dspotbugs.skip clean install

This may take a little time. If everything works well, you should get a successful build result like below:

build1

Now, we can run Jenkins on our local machine using the following command:

mvn -pl war jetty:run

If it runs successfully, you should be able to view Jenkins console by going to http://localhost:8080/jenkins/

build2

4. Debugging

Now, our next goal is to be able to debug Jenkins by using breakpoints in IntelliJ. Close the previous running instance by (Ctr+c).

debug1

In the toolbar, go to Run → Edit Configurations…

debug2

Click on the ‘+’ icon so we can add a new configuration.

debug3

Click on ‘Maven’.

debug4

Ensure that this configuration is the same as above. Click on Apply and OK.

debug5

Now, you can choose either Run ‘Maven Run’ or Debug ‘Maven Run’ based on what you would like to do. Breakpoints can easily be applied alongside the code in the IDE.

Moreover, Groovy/Jelly views are re-compiled every time a browser requests a page so that the changes can be observed with just a simple browser refresh. This is also true for help files.

Also, you can run ‘Build’ in IntelliJ to hot-swap code, which means that some changes like method bodies and annotations changes will take effect without having to restart Jenkins.