How to Debug Jenkins remotely

Thanks Jenkins Maven HPI Plugin, you can do the most Jenkins plugin development stuff locally. But in some cases, you have to debug a Jenkins instance remotely (In my case, the Jenkins had to run in Azure to reproduce a bug).

Jenkins is a Java application, so you have to add Java's JDWP agent for debugging as Java argument to Jenkins config

1-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000 // for JDK 9 or later

The big question is, where is the configuration file on the machine to do it.

Answer: It depends on your operating system 🤓

Fortunately, Cloudbees has a good overview where to find the configuration files depend on the operating system .

In my case, I use Ubuntu as operating system. On Ubuntu, the configuration file is /etc/default/jenkins. I can extend the system environment variable JAVA_ARGS, there (see sample below).

 1# defaults for Jenkins automation server
 2
 3# pulled in from the init script; makes things easier.
 4NAME=jenkins
 5
 6# arguments to pass to java
 7
 8# Allow graphs etc. to work even when an X server is present
 9JAVA_ARGS="-Djava.awt.headless=true"
10
11JAVA_ARGS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000"
12
13# more configuration stuff

Then restart your Jenkins instance (sudo service jenkins restart). Then you should see in Jenkins log (default on Ubuntu: /var/log/jenkins/jenkins.log) the following snippet:

1Listening for transport dt_socket at address: 8000

Now, you can connect your IDE via Remote Debug to your Jenkins instance.