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.
- Tried restarting Hudson - didn't solve it.
- 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) - 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
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
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
)
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'
For anyone else looking into this issue, one workaround that I arrived at was to run a standard windows batch command from within a Jenkins job that sets the execution policy:
powershell.exe -command set-executionpolicy unrestricted
For some reason the policy being used by Jenkins was overriding the machine-wide policy. Running set-executionpolicy from within Jenkins was a quick way to make sure that the policy specific to the Jenkins environment was being set.
精彩评论