2

Right now sorting out a good workflow using Jenkinsfiles is a bit slow since I have to create a job, and run it from the UI in order to get feedback on whether or not it works.

I was wondering if there was a way to place a breakpoint inside of a Jenkinsfile that way I could toy around and get a feel for the libraries / methods / variables that are available.

Is this something that is possible? Or do I have to stick to my current process of editing a Jenkinsfile in the Jenkins UI and then re-running the build?

--Edit--

I've found a workflow that works a little faster than making changes through the UI. The SSH server within Jenkins exposes a command called declarative-linter and one called replay-pipeline. Now I just develop the script locally and rerun these commands after I make an edit.

So basically, my workflow is like this:

  • Edit the script to my liking
  • Run the lint check. I have jenkins setup in my ssh config file, so basically I run this using Powershell:

gc Jenkinsfile | ssh jenkins declarative-linter

  • Run the newly changed script by replaying a pipeline build:

gc Jenkinsfile | ssh jenkins replay-pipeline <name of my job with branch name>

  • Run the console command to tail the logs:

ssh jenkins console <name of my job with branch name>

All I did was wrap these lines into a PowerShell function and after I edit the script locally I run one command to perform all this to validate the change. It's definitely more complicated, but the turn around time is a bit faster than it was using the Jenkins UI, plus I get to edit the script using my favorite editor. Hopefully, in the future, there will be better tooling around debugging Jenkinsfiles.

arjabbar
  • 6,044
  • 4
  • 30
  • 46

2 Answers2

2

This is the only way currently. Although I know that there requests for future additions in this direction (Pipeline debugger). Probably there are some options to debug this directly from Java, but this is not a trivial setup to be done.

nradev
  • 113
  • 5
0

Add an user input

input message: "Continue?"

pipeline input step, Read interactive input in Jenkins pipeline to a variable

Hans Ginzel
  • 8,192
  • 3
  • 24
  • 22