Great Article! But one thing I could not wrap my Head around, how do you mock steps.node? I can't figure it out on how to test my sh command which is inside of a node...
You are using a Scripted Pipeline, right? Not sure how you could mock the node step (or any step that uses closures for that matter) as I'm only familiar with Declarative Pipelines. Sorry 🙈
Keep in mind that the goal of this article is to test your Jenkins Pipeline Library. Not the pipeline itself (aka the Jenkinsfile).
My problem was to figure out what signature the method node had. This was
caused by the fact, that I did not know, that node("<name>") {} is the
same as node("<name>", {}).
So for anyone wondering how to mock the closure methods, this is the way.
@kuperadrian
maybe you could include this in your article to help anyone who is in need of mocking a closure :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great Article! But one thing I could not wrap my Head around, how do you mock
steps.node
? I can't figure it out on how to test mysh
command which is inside of anode
...You are using a Scripted Pipeline, right? Not sure how you could mock the
node
step (or any step that uses closures for that matter) as I'm only familiar with Declarative Pipelines. Sorry 🙈Keep in mind that the goal of this article is to test your Jenkins Pipeline Library. Not the pipeline itself (aka the Jenkinsfile).
Thank you for the reply.
Yes I'm using the Scripted Pipeline, but I use my SL to do some things on nodes. Anyway, I figured it out just now.
The following is my current code to mock
node("<name>") {}
:My problem was to figure out what signature the method node had. This was
caused by the fact, that I did not know, that
node("<name>") {}
is thesame as
node("<name>", {})
.So for anyone wondering how to mock the closure methods, this is the way.
@kuperadrian maybe you could include this in your article to help anyone who is in need of mocking a closure :)