I am trying to create a new Pipeline Step as a plugin, but I don’t know how to get the internal plugin code to run on the agent. I naively started by simply changing an existing step with a very crude and ugly change for learning purposes:
When I manually deploy this plugin and run it, the internal logger statements report that the code runs on the Jenkins controller, not on the agent.
How to I get the code of the plugin to run on the agent?
Typically, a plugin running on an agent uses the associated workspace. This workspace instance (type is FilePath) has a method act() that runs the code on the agent.
Thanks, always nice to learn the Jenkins features. One thing I want is a shell step that returns two strings (stdout and stderr) and an integer. Could this go as far as to support something like running an external process, i.e. FilePath.act(new FileCallableBashProcess(String theBashScript)) ? Or would that push it too far?
I’m not sure if I understand your question. You can basically run anything on the agent. Such a step can return a serializable Object that contains strings and integers.
But running a bash script might be a security risk, is this file under your control?
When you want to invoke scripts on the agent, then there are other APIs available, that should be better used. (I have not yet used them.)
Valid point however in my context I have no concern being OS specific. We use the sh step everywhere in our Jenkins code since this is exclusively for a linux based environment.