Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

I can run a powershell script on Jenkins using a "Execute windows batch command" build step with the following command:

powershell -ExecutionPolicy ByPass -File script.ps1

But I am unable to run a powershell script with the Jenkins "Powershell plugin" using the "Windows Powershell" build step and this command, because of a Windows Execution policy not set error disallowing it to run:

script.ps1

Does anyone know the proper arg to give the Jenkins "Powershell Plugin" for it to succesfully run a script? Otherwise, I will just use the batch script work-around.

like image 806
djangofan Avatar asked Feb 16 '23 15:02

djangofan


1 Answers

The correct thing to do is to set an execution policy on your machine (a one-time action), at which point you won't need to bypass it every time, and the Jenkins plugin should "just work". Are you unable to?

A reasonable starting setting would be RemoteSigned, which will allow you to execute local scripts fine but would still disallow scripts downloaded from the internet.

From an elevated PowerShell prompt, you would run:

Set-ExecutionPolicy RemoteSigned

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

UPDATE: excerpt from Help on applying policy and how it's supposed to behave:

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

Of course, if your machine is on a Domain, then Group Policy could revert this.

like image 195
Joshua McKinnon Avatar answered Feb 23 '23 01:02

Joshua McKinnon