How to get Hudson CI to execute a Powershell script?

Question:

I’m using Hudson version 1.324 for CI and have a couple of issues:

Environment:

  • Windows Server 2008
  • Powershell v1.0
  • Hudson 1.324 running as a service
  • Hudson Powershell Plugin installed
  • Psake (aka. “Powershell Make/Rake” available from Github) 0.23
    (All current/latest versions as of this initial post)

I have a Powershell (PS) script that works to compile, run NUnit tests, and if successful, create a 7z file of the output. The PS script works from the command line, on both my local development box as well as the CI server where Hudson is installed.

1) Execution Policy with Powershell.

I initially ran a PS console on the server, ran Set-ExecutionPolicy Unrestricted, which allows any script to be run. (Yes, I realize the security concerns here, I’m trying to get something to work and Unrestricted should remove the security issues so I can focus on other problems.)

[This worked, and allowed me to fire off the PS build script from Hudson yesterday. I then encountered another problem, but we’ll discuss that more in item #2.]

Once Hudson could fire off a PS script, it complained with the following error:

“C:\Windows\system32\WindowsPowerShell\v1.0\powershell “&
‘OzSystems.Tools\psake\psake.ps1’ ‘.\oz-build.ps1′” The term
‘OzSystems.Tools\psake\psake.ps1’ is not recognized as a cmdlet, funct
ion, operable program, or script file. Verify the term and try again.
At line:1 char:2
+ & <<<< ‘OzSystems.Tools\psake\psake.ps1’ ‘.\oz-build.ps1′”

Using the same command line, I am able to successfully execute the PS script from the command line manually. However Hudson is unable to get PS to do the same. After looking at additional PS documentation I also tried this:

and got a similar error. There does not appear to be any documentation for the Powershell plugin for Hudson. I’ve gone through all the Powershell plugin files and don’t see anything that’s configurable. I can’t find a log file for Hudson to get additional information.

Can anyone help me past this?

2) I spent yesterday wrestling with #1. I came in this AM and tried to dig in again, after restarting the Hudson server/service, and now it appears that the ExecutionPolicy has been reset to Restricted. I did what worked yesterday, opened a PS console and Set-ExecutionPolicy to Unrestricted. It shows Unrestricted in the PS console, but Hudson says that it doesn’t have rights to execution PS scripts. I reopened a new PS console and confirmed that the ExecutionPolicy is still Unrestriced — it is. But Hudson evidently is not aware of this change. Restarting Hudson service again does not change Hudson’s view of the policy.

Does anyone know what’s going on here?

Thanks, Derek

Answer:

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 administrator
2. Set the execution policy to remotesigned

Run this once and your homefree.

Source:

How to get Hudson CI to execute a Powershell script? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply