Excute powershell script from plugin on remote machine

7 views
Skip to first unread message

Rajeev Ranjan

unread,
Aug 6, 2019, 8:28:40 AM8/6/19
to Jenkins Developers
Hi team,
My plugin is downloading a powershell script and is executing that. I was using Powershell Plugin itself, but problem with this is it fails while executing pipeline script.
throwing ClassCastException  WorkflowRun cannot be cast to AbstractBuild
exception.png
 With some basic search in the group I believe it is not the right to cast Run to AbstractBuild
Creating own ProcessBuilder executes the step on current machine instead of slave, which is why I want to use CommandInterpreter.

Is there any other suggested way to execute the powershell script to use the same?

Rajeev Ranjan

unread,
Aug 6, 2019, 9:56:29 AM8/6/19
to Jenkins Developers
Currently I am trying to do something like this 
new PowerShell(<commands>).perform((AbstractBuild<?, ?>) run, launcher, listener)

Jesse Glick

unread,
Aug 6, 2019, 2:16:57 PM8/6/19
to Jenkins Dev
On Tue, Aug 6, 2019 at 8:28 AM Rajeev Ranjan <rajeevr...@gmail.com> wrote:
> Creating own ProcessBuilder executes the step on current machine instead of slave, which is why I want to use CommandInterpreter.

You can use `Launcher`.

Baptiste Mathus

unread,
Aug 6, 2019, 4:26:16 PM8/6/19
to Jenkins Developers
Why are you casting into AbstractBuild? If this is what the powershell plugin expects, then a fix seems indeed needed there to accept a Run instead.
If it already does, remove your cast.

(Cannot check myself, low to no bandwidth connection to Internet currently)

Le mar. 6 août 2019 à 15:56, Rajeev Ranjan <rajeevr...@gmail.com> a écrit :
Currently I am trying to do something like this 
new PowerShell(<commands>).perform((AbstractBuild<?, ?>) run, launcher, listener)

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/582135c0-5ebc-4e36-b884-72c7e736d110%40googlegroups.com.

Rajeev Ranjan

unread,
Aug 7, 2019, 3:59:15 AM8/7/19
to Jenkins Developers
Yes, Powershell plugin extends CommandInterpreter whose perform accepts AbstractBuild, not Run.
For normal use case it works fine, but it fails for pipeline.

On Wednesday, August 7, 2019 at 1:56:16 AM UTC+5:30, Baptiste Mathus wrote:
Why are you casting into AbstractBuild? If this is what the powershell plugin expects, then a fix seems indeed needed there to accept a Run instead.
If it already does, remove your cast.

(Cannot check myself, low to no bandwidth connection to Internet currently)

Le mar. 6 août 2019 à 15:56, Rajeev Ranjan <rajeevr...@gmail.com> a écrit :
Currently I am trying to do something like this 
new PowerShell(<commands>).perform((AbstractBuild<?, ?>) run, launcher, listener)

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkin...@googlegroups.com.

Rajeev Ranjan

unread,
Aug 7, 2019, 3:59:43 AM8/7/19
to Jenkins Developers
Thanks Jesse, I will give this a try
Reply all
Reply to author
Forward
0 new messages