This article is a walk-through guide on how to setup IntelliJ IDEA to develop and debug Jenkins core.
Index:
Installation and Cloning
Setting up IntelliJ IDEA
Building Jenkins
Debugging
Install IntelliJ using the Installation guide.
The minimum Apache Maven version for Jenkins development is 3.8.1. Refer to Troubleshooting common Maven issues if needed.
Fork from the Jenkins core source code.
Clone the forked repository to your machine. In this tutorial, IntelliJ IDEA Version 2019.3.1 is used.
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 Next
Click on Next
Click on Next
Click on Finish. IntelliJ should be ready like below.
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:
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/
Now, our next goal is to be able to debug Jenkins by using breakpoints in IntelliJ. Close the previous running instance by (Ctr+c).
In the toolbar, go to Run → Edit Configurations…
Click on the ‘+’ icon so we can add a new configuration.
Click on ‘Maven’.
Ensure that this configuration is the same as above. Click on Apply and OK.
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.