"IntelliJ 7.0 (or later) users can load pom.xml directly from IDE, and you should see all the source code of libraries and Jenkins core all the way to the bottom. Consider installing IntelliJ IDEA plugin for Stapler to make the development easier."
1. Install Maven3 and create ~/.m2/settings.xml according to https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorial.
2. git clone email@example.com:jenkinsci/git-client-plugin.git (or whatever plug-in you want to troubleshoot)
3. Edit the pom.xml to match the current Jenkins release you're using. I found that I needed to test on v1.549 simply older versions were not able to support some of the newer plugins that have been breaking.
<parent> <groupId>org.jenkins-ci.plugins</groupId> <artifactId>plugin</artifactId> <version>1.549</version> </parent>3. Open up IntelliJ and import the pom.xml file as a new Project. The dependent modules should be listed.
4. Go to IntelliJ IDEA -> Preferences. Find Maven. Make sure all the appropriate directories are setup. You shouldn't have to make any changes but the Maven home directory should be setup if you've correctly installed it.
5. Go to Tool Windows -> Maven Projects.
6. The Maven Projects window should appear on the right. Make sure that the Jenkins profile is clicked. Click on the package Lifestyle, which should start triggering the dependencies to be downloaded.
7. Once dependencies have been retrieved, the Plugins section should appear. Find the hpi Plugin, which will allow you to spawn a Jetty server and setup breakpoints for your plug-in. Right click on the hpi:run option in the menu and run as Debug mode.
8. You can then access http://localhost:8080/jenkins, which should give you the landing screen for Jenkins.
All the Jenkins-specific configurations are done within a work/ directory, so if you decide to open a new project for a different plug-in, you can setup a completely new Jenkins environment. If you decide to make a code-change, just stop the debugging and restart. The plug-in will be recompiled and the Jetty web server will be restarted. Any breakpoints and variable inspection can also be done.
I used this approach to diagnose issues with Jenkins' git-client-plugin, which has had a whole host of problems recently. For instance, there were several revisions leading up to v1.6.1 (which is currently the latest release) that simply didn't work -- the syntax to call Git was plain wrong.
The latest v1.6.2 snapshot has problems with Git repos that rely on HTTP-based credentials. One issue occurs in the shared use of a function that attempts to validate a repo URL. There are assumptions that an existing Git workspace exists, which aren't true if you're first trying to configure a new build job. By setting breakpoints to where the offending issue was occurring, I was able to pinpoint quickly and introduce a PR to the discussion below: