0

I am running docker on a Debian 9 machine, and a Jenkins container in it. I installed the PowerShell plugin in Jenkins and I am trying to run a PowerShell script, but I get a message saying that it can't find Powershell.exe (duh!)

I don't want to run docker on Windows. Is there a way to make PowerShell work on a Jenkins container running on a Linux machine?

Caused:

java.io.IOException: Cannot run program "powershell.exe" (in directory "/var/jenkins_home/workspace/Revert Plugin"): error=2, No such file or directory

EBGreen
  • 1,453
  • 11
  • 10
aristosv
  • 147
  • 4
  • 14
  • Powershell v6 is cross platform and can be installed on Linux as far as I know. Having said that, it does not have anywhere near the number of comdlets that powershell v5 does. So if you expect to take a powershell script that was written to run on windows then run that script on linux, the script will have to be very simplistic or you will have to be very lucky. – EBGreen May 14 '18 at 16:55
  • This is the error. Caused: java.io.IOException: Cannot run program "powershell.exe" (in directory "/var/jenkins_home/workspace/Revert Plugin"): error=2, No such file or directory – aristosv May 14 '18 at 16:58
  • So it sounds like you need to get powershell installed then make sure jenkins knows where to find it. Also, always add new information by editing your question. – EBGreen May 14 '18 at 17:00
  • This was really not helpful. – aristosv May 14 '18 at 17:07
  • I don't know what else to tell you. That is what the error indicates. I suppose I could paste the link for the document on [how to install powershell on linux](https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-powershell-core-on-linux?view=powershell-6) but that was a simple google search that I thought was obvious. – EBGreen May 14 '18 at 17:14
  • Do you want build artifacts for Windows with Jenkins? In that case running [Jenkins agent](https://plugins.jenkins.io/windows-slaves) on a Windows host would be a obvious solution. – Henrik Pingel May 14 '18 at 17:23
  • What is in the script? That would determine if you need to ru. Windows powershell or powershell core (pwsh.exe) – Semicolon May 14 '18 at 21:42

2 Answers2

0

According to the documentation, the Jenkins Powershell plugin provides integration with "Windows PowerShell" Which is not the same as the cross platform Powershell (Core). It is very likely that this is not the setup you are looking for. You may be able to rewrite the powershell script to allow it to run on linux, but you would also likely have to install powershell (core) on the windows resources to be managed, and possibly also install OpenSSH on the windows resources.

Semicolon
  • 1,775
  • 8
  • 7
0

Another idea: after installing powershell core, at the cli you should now have pwsh available. Create an alias: powershell pointing at pwsh.

Something like this should suffice: echo "alias powershell=pwsh" >> /Users/`(whoami)`/.profile . /Users/`(whoami)`/.profile

verify using:

powershell

BE77Y
  • 2,667
  • 3
  • 18
  • 23
peter
  • 1