How to get Hudson CI to execute a Powershell script? How to get Hudson CI to execute a Powershell script? powershell powershell

How to get Hudson CI to execute a Powershell script?


I just ran into the problem of running powershell scripts in hudson. The thing is that you are running a 32-bit process of Java, and you've configured Hudson for 64-bit but not for 32-bit. See the following thread we created at microsoft.

http://social.technet.microsoft.com/Forums/en/winserverpowershell/thread/a9c08f7e-c557-46eb-b8a6-a19ba457e26d

If your lazy.1. Start powershell (x86) from the start menu as administrator2. Set the execution policy to remotesigned

Run this once and your homefree.


When Running PowerShell from a scheduled task or Hudson you want to:

  1. Specify the -ExecutionPolicy parameter (in your case: -Ex Unrestricted)
  2. Specify that command using either -Command { ... } or -File NOT BOTH and not without specifying which you mean.

Try this (except that I don't recommend using relative paths):

PowerShell.exe -Ex Unrestricted -Command "C:\Path\To\OzSystems.Tools\psake\psake.ps1" ".\oz-build.ps1"

To be clear, this will work too:

PowerShell.exe -Ex Unrestricted -Command "&{&'OzSystems.Tools\psake\psake.ps1' '.\oz-build.ps1'}"

The first string after -Command is interpreted as THE NAME OF A COMMAND, and every parameter after that is just passed to that command as a parameter. The string is NOT a script, it's the name of a command (in this case, a script file)... you cannot put "&'OzSystems.Tools\psake\psake.ps1'" but you can put "OzSystems.Tools\psake\psake.ps1" even if it has spaces.

To quote from the help (run PowerShell -?) emphasis mine:

-Command

Executes the specified commands (and any parameters) as though they were typed at the Windows PowerShell command prompt, and then exits, unless NoExit is specified. The value of Command can be "-", a string. or a script block.

If the value of Command is "-", the command text is read from standard input.

If the value of Command is a script block, the script block must be enclosed in braces ({}). You can specify a script block only when running PowerShell.exe in Windows PowerShell. The results of the script block are returned to the parent shell as deserialized XML objects, not live objects.

If the value of Command is a string, Command must be the last parameter in the command , because any characters typed after the command are interpreted as the command arguments.


I have been having the same problems as you (as you've seen from my comments). I have given up on the powershell launcher and moved to running things using the batch file launcher. Even though I had set the system to unrestricted that setting didn't seem to matter to hudson's launcher. I don't know if it runs in some other context or something, even adding things to the global profile.ps1 didn't seem to help. What I ended up doing was running

powershell " set-executionpolicy Unrestricted; & 'somefile.ps1'" 

which does what I need, although it isn't ideal. I've e-mailed the plugin author about this and will update.