-
Suggestion
-
Resolution: Unresolved
-
None
-
None
-
1
-
Problem Definition
At the moment the Bamboo Script task does not support running Windows Powershell commands on Linux.
If you follow the Install PowerShell on Linux guide and attempt to add a Script task to Bamboo with the Interpreter set to Windows PowerShell to run on a Linux agent the task will fail because Bamboo adds /bin/sh to the command.
Here's an example from a build that failed to run a Get-Help inline script with the Windows PowerShell interpreter on a Linux agent:
simple 02-Feb-2022 14:31:38 Failing task since return code of [powershell -NonInteractive -ExecutionPolicy bypass -Command /bin/sh /var/atlassian/application-data/bamboo/temp/PROJ-PS-JOB1-4-ScriptBuildTask-2968191361645146443.ps1] was 1 while expected 0
Since Bamboo doesn't support pwsh yet (BAM-20854) you might have to create a symbolic link from pwsh pointing to powershell to workaround this limitation:
ln -s /usr/bin/pwsh /usr/bin/powershell
Suggested Solution
A couple of ideas:
- Add a new interpreter to the Script task to account for the Linux version of Windows PowerShell.
- Skip appending of the /bin/sh command when the interpreter is set to Windows PowerShell regardless of the environment detected by Bamboo/ agent.
Workaround
Use the Shell interpreter rather than Windows PowerShell and add the following shebang line to your script (whether inline or from a file):
#!/usr/bin/env powershell
#!/usr/bin/env pwsh