views:

83

answers:

3

Hi Folks,

Encountered a problem executing Powershell scripts from Hudson CI server using the Powershell Plugin. 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.

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 instead 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 + -ExecutionPolicy Unrestricted" - I assume because I 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

A: 

Since the comments in the Hudson PowerShell Plugin mention also this issue, you could revert to a script with:

" powershell.exe "& 'script.ps1'" "

That same script could make sure to set the Policy accordingly (RemoteSigned or Unrestricted)

VonC
Yeah, tried this too. It seems to "hang" the job (i.e. not getting anything in console output) and I can look elsewhere on the system and see that its not actually doing anything. Started it about 6mins ago and still not getting any output :( Doesn't look good basically!!!
jamiet
@jamiet: not good indeed. Has the account used by Hudson any Administrator privileges?
VonC
Yep it has! Anyway, sod it, I've persuaded the server admins to let me install Powershell v2.0 so I'm crossing my fingers that using -ExecutionPolicy will solve it. Watch this space (I shall report back)
jamiet
No, you cannot set the execution policy inside the script, because just trying to run the script requires an execution policy be changed properly.
Marco Shaw
A: 

It sounds like the Hudson CI Server may be running under a different user account than the one from which your are setting the execution policy. If that is the case then log in as that user and set the execution policy. If this is a service running under a built-in account, you could try creating special account, configuring the service to use that account and set the execution policy on that. Short of that, upgrade to PowerShell 2.0 and pass the policy in on the comand line as you attempted (which is not supported on 1.0).

Another approach is to set execution policy machine-wide via either GPO or a reg key:

HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell 

and set the ExecutionPolicy value to 'RemoteSigned' or 'Unrestricted'

Keith Hill
Hi Keith,Yeah, already tried that (i.e. logging in as the user running Hudson). It doesn't work.I'll go and speak to the server team about putting 2.0 on there. Experience tells me they're not going to be very helpful :(-Jamie
jamiet
Another approach is to set execution policy machine-wide via either GPO or a reg key - HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell and set the ExecutionPolicy value to 'RemoteSigned' or 'Unrestricted'.
Keith Hill
Hi Keith. Ah, didn't know I could do that. Unfortunately I've taken a look and its already set to RemoteSigned <sigh> Another door slams in my face, this is truly baffling.Thanks for the suggestion anyhow keith.
jamiet
A: 

Hi all,

Good news. Installing Powershell v2 seems to have solved the problem. I'm not 100% sure all problems have gone away but I can successfully execute Powershell commands using the Powershell plugin for Hudson and that is good news.

Thanks to all for the help and I hope this thread proves useful to folks in the future.

Regards Jamie

jamiet