Why can't I use the Jenkins Powershell plugin?

Why can't I get Jenkins "Powershell plugin" to work?

I can run the powershell script on Jenkins using the “Execute Windows Batch Command” build step with the following command:

powershell -ExecutionPolicy ByPass -File script.ps1 

But I can’t start the powershell script using the Powershell Jenkins plug-in using the Windows Powershell build step, and this command, due to the Windows Execution policy, does not fix an error preventing it from running:

 script.ps1 

Does anyone know of a suitable argument to give Jenkins a "Powershell plugin" so that he successfully runs the script? Otherwise, I just use a script workflow.

+4
source share
3 answers

The right thing is to install the execution policy on your computer (a one-time action), after which you will not need to bypass it every time, and the Jenkins plugin should "just work". You can not?

A sensible starting parameter would be RemoteSigned, which will allow you to execute local scripts in order, but will still prohibit scripts downloaded from the Internet.

At the extended PowerShell prompt, you should run:

 Set-ExecutionPolicy RemoteSigned 

See also: http://technet.microsoft.com/library/hh849812.aspx

UPDATE: excerpt from the certificate on the application of the policy and how it should behave:

If you set the execution policy for the local computer (by default) or the current user, the change is saved in the registry and remains until you change it again.

Of course, if your machine is in a domain, Group Policy can return it.

+3
source

For a solution with a reboot, put this single line

powershell Set-ExecutionPolicy -Scope CurrentUser RemoteSigned -Force

in the batch file in the "Startup for all users" folder, which in Windows 7 C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

(or you can get there by clicking "Start" → "All Programs", right-click "Run" and select "Open All Users").

This is how I got Jenkins executing PS scripts on a domain machine subject to Group Policy without involving the sys admin guys :-)

+3
source

After experimenting, I realized that since Jenkins works as a service as a System user, then the powershell authority is different from the one used by the terminal services login session.

This script works for me and seems to set the registry keys correctly so that this setting is constant on reboots and new entries.

 # SetExecutionPolicyToRemoteSigned.ps1 # Need to run this after every server reboot. Write-Output "Setting local Powershell policy to RemoteSigned" Write-Output "" Set-ExecutionPolicy -scope CurrentUser Undefined -Force #Set-ExecutionPolicy -scope Process Undefined -Force Set-ExecutionPolicy -scope LocalMachine Undefined -Force Set-ExecutionPolicy -scope CurrentUser RemoteSigned -Force #Set-ExecutionPolicy -scope Process RemoteSigned -Force Set-ExecutionPolicy -scope LocalMachine RemoteSigned -Force Write-Output "Finished." Get-ExecutionPolicy -list Start-Sleep -s 10 
+2
source

Source: https://habr.com/ru/post/1496065/


All Articles