debugging jenkinsfiles

As a DevOps I spend a lot of time in Jenkins, automating stuff. Often pipelines will misbehave and I need ways of debugging things:


Obviously the easiest way of getting information out of the running pipeline.

Simulating a “breakpoint”

Adding a


somewhere in the pipeline pauses execution at that point which lets me check the workspace folder, even see containers that Jenkins is running and SSH into them to see what’s what.

A REPL function

In Adam Saleh – Debugging Jenkins pipeline I found this nifty Loop to execute arbitrary code during execution to “live debug” actual values in the environment of the pipeline:

while (true)
    def cmd = input message: 'What to run:', parameters: [string(defaultValue: '', description: '', name: 'cmd')]
    try {
        print Eval.x(this,cmd)
    } catch (e) {
        print e

You can then input code to execute in this case, something like:

x.binding.steps.invokeMethod("sh","node --version")