views:

824

answers:

4

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:

"& 'OzSystems.Tools\psake\psake.ps1' '.\oz-build.ps1'"

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

+1  A: 

For question #1, try this (assuming you are using PowerShell 2.0):

"C:\Windows\system32\WindowsPowerShell\v1.0\powershell -executionPolicy Unrestricted -file OzSystems.Tools\psake\psake.ps1 C:\{path}\oz-build.ps1"

You are using "." for the path to oz-build.ps1. I suspect you will need to provide the full path to your oz-build.ps1 file to make this work. Unless the infrastructure that executes the command above happens to have the current dir set correctly. And even if it is set correctly for the "process", that only matters to .NET/Win32 API calls and not to PowerShell cmdlets. Current dir in PowerShell is tracked differently than the process's current dir because PowerShell can have multiple runspaces running simultaneously. That sort of global, mutable value doesn't work in this concurrent scenario.

As for question #2, what account does the Hudson service run under? Make sure that account has executed Set-ExecutionPolicy RemoteSigned (or unrestricted).

Keith Hill
Keith,I've tried the suggestions for #1. Same problems.For #2, Yes, I have made sure the ExecutionPolicy is set for the account that Hudson is running under. It is Unrestricted when I log in manually to check the ExecutionPolicy. Hudson's still saying that scripts are disabled.We're about to punt on Powershell and try Rake with Hudson. It appears PS is not quite ready for prime time, or at least not behaving consistently enough for us to rely on.Thanks for the input Keith!
Before giving up, try using the -ExecutionPolicy Unrestricted parameter. I've modified the example above to show this.
Keith Hill
+1  A: 

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.

stimms
+1  A: 

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.

Jaykul
A: 

Folks, Encountered this thread because I seem to be having exactly the same issues. I'm running:

  • Hudson v1.362
  • Windows 2003
  • Powershell 1.0

I am trying to use the Powershell plugin for Hudson. Anything I try just gives me:

File C:\DOCUME~1\SVC_PR~1\LOCALS~1\Temp\hudson2144883754471568213.ps1 cannot be loaded because the execution of scripts is disabled on this system.

Just like quikdraw2700 I have set the ExecutionPolicy as "Unrestricted" but still I get the same message in Hudson.

  1. Tried restarting Hudson - didn't solve it.

  2. Tried putting "Set-ExecutionPolicy Unrestricted" in the Powershell profile of the account running Hudson, that only succeeded in giving me the above message twice insted of once (oh the irony)

  3. Tried issuing from the command-line "Powershell -ExecutionPolicy Unrestricted". That returned error: "Missing expression after unary operator '-'. At line:1 char:2 + -E <<<< xecutionPolicy Unresticted" - I assume becauseI am using Powershell 1 and -ExecutionPolicy is not a v1 option.

So I'm stuck. Any advice as to how to get Hudson to run Powershell scripts using this Poweshell plugin would be most welcome.

Thanks Jamie

jamiet
Please don't treat StackOverflow like a forum. If you have an answer or comment please contribute to this question in that form otherwise if you have a question of your own post a new question and link back to this one if you think it would be useful.
jpierson