Powershell is failing bamboo task because -ExecutionPolicy bypass -Command return code is 134 instead of 0
Asked Answered
F

1

8

I have a powershell script that will be ran in Bamboo that will update the status of the Bamboo build. This is called in Github and then the status will be update whatever build that calls the script. This is currently working fine in a windows machine but now there are builds that are needed on a Mac machine.

Firstly the script was returning the error code -1 because I did not have powershell installed on the Mac. Now that I have installed powershell, I am getting the following error:

Failing task since return code of [powershell -ExecutionPolicy bypass -Command /bin/sh /var/folders/c6/T/MAC-CUSAPP-JOB1-14-ScriptBuildTask.ps1] was 134 while expected 0

The code itself is fine for windows as all other builds using a windows agent on bamboo will successfully build the task.

& "${bamboo.build.working.directory}\scripts\publish-status.ps1" `
    -repoName MyRepo `
    -status pending `
    -revision ${bamboo.repository.revision.number} `
    -buildUrl ${bamboo.buildResultsUrl} `
    -description "Bamboo has started a build" `
    -context "bamboo-build"

Is there anyway of doing this correctly so that this will work for a Mac. Currently I have checked that the windows machine in running Powershell Version 5.0.0+ while the Mac is Powershell 6.0.0 Alpha would this be the reason that it is not building and giving the error code of 134?

When I even tried to do this:

if (2 -lt 3)
{
 Write-Host this is lower
}
else
{
 Write-Host this is higher
}

It will give the same response, even if I did Write-Host hello it would respond with the return code of 134.

Even using a simple powershell script that says return 0 will still give the error message of the return code being 134. Also I checked the ExecutionPolicy for the machine and it is unrestricted for everything.

Also the problem is not the powershell on the Mac, as it will successfully run a powershell script perfectly but it is how bamboo is using the powershell script on the Mac. Do you need to do something different when using a powershell script on bamboo whilst you are using a Mac?

Here is am image of how I run the Bamboo, it's a script task that's needed on windows but this doesn't work on a mac. enter image description here Update

I added powershell as an executable and then used a command task to call the powershell file but this still not work, any idea's if it is because of Bamboo not supporting powershell on the mac as powershell work's using visual studio code and the terminal on the mac. I did it two ways like this:

-ExecutionPolicy Bypass -File /Users/dev/Documents/PowreshellScripts/hello.ps1

and also like this:

-NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -File /Users/dev/Documents/PowreshellScripts/hello.ps1
Finnell answered 28/11, 2016 at 15:6 Comment(16)
just to narrow down the problem can you try running the script on a mac outside of bamboo and see what the return code is and if any errors get generated during the run? from my understanding not everything is implemented on mac yet and that could be creating an issue.Calabrese
that I'm not sure of but the error message seems to indicate that the script is running and exiting with error code 134, is that an error your script is set up to generate? and if so can you show the code nearby?Calabrese
so unless I'm completely misunderstanding that error message something is causing the powershell process to finish with a code of 134 rather than 0, which is why I was suspecting that the script had some step where it could return that code if something failed, which could let you know what portion of the script could not be implemented on mac. if you'd like to test if powershell can work at all on the mac via bamboo try creating a test job that does noting but return 0 and sending it to a mac to see if it works.Calabrese
Yeah that will return the same error 134Finnell
ok, then the problem is either something permissions related on the mac or the bamboo agent can not yet open powershell on the mac. Only other potential fix I can think of would be to swap powershell -ExecutionPolicy bypass -Command /bin/sh /var/folders/c6/T/MAC-CUSAPP-JOB1-14-ScriptBuildTask.ps1 for powershell -ExecutionPolicy bypass -file /var/folders/c6/T/MAC-CUSAPP-JOB1-14-ScriptBuildTask.ps1 just to see if there is an issue with that call signatureCalabrese
The powershell -ExecutionPolicy bypass -Command /bin/sh /var/folders/c6/T/MAC-CUSAPP-JOB1-14-ScriptBuildTask.ps1 is just an error message I can't change that.Finnell
Oh I figured that was the command the job was launching with, which I assumed would be configurable. but if not last thing to check would be permissions.Calabrese
Your command string is not quoted in your example or comments. I would guess it is just running sh with no arguments or something like that.Representation
The command string @Representation is referring to is what follows -Command, i.e., in -Command /bin/sh /var/folders/c6/T/MAC-CUSAPP-JOB1-14-ScriptBuildTask.ps1, the command string is ` /bin/sh /var/folders/c6/T/MAC-CUSAPP-JOB1-14-ScriptBuildTask.ps1. Given that /var/folders/c6/T/MAC-CUSAPP-JOB1-14-ScriptBuildTask.ps1` is a powershell script, why is /bin/sh involved at all? It seems to me that you should be able to invoke your scriptbuildtask script as powershell -ExecutionPolicy Bypass -File /var/folders/c6/T/MAC-CUSAPP-JOB1-14-ScriptBuildTask.ps1, possibly with an optional -NoProfile.Irish
That's just an error message I can't do anything about why /bin/sh is involved. The powershell runs on windows without any command string so I should not need it on a macFinnell
We get that its an error message but it's also showing that in the background bamboo is telling powershell to run the command bin/sh /var/folders/c6/T/MAC-CUSAPP-JOB1-14-ScriptBuildTask.ps1, meaning it will try and load the mac shell and then have the mac shell attempt to execute your powershell code, obviously that's not what you want to have happen. what options are you able to configure within bamboo that are related to the script execution?Calabrese
@MikeGaruccio What I do is this, Add Script Task, check Run as Powershell Script, type the Powershell into the Script Body that worked fine on windows but isn't on the mac, there are also the following fields, Argument: to pass to the command. Extra Variables: Extra environment Variables and Working Sub directory which specifies an alternative sub-directory.Finnell
Can you show how you tried to run the Write-Host "hello" command? I would like to see that definition.Representation
@Representation I added an Image and explained a bit about it.Finnell
Are you passing anything to the argument field?Calabrese
I shouldn't need to unless on a mac it is differentFinnell
L
1

I've had a cursory Google of the issue and it looks like this is actually a bug with PowerShell for Linux (and MacOS by proxy), at least according to the PowerShell for Mac GitHub issue I managed to find for it. The user who reported the issue with PowerShell seems to have a very similar issue with the -ExecutionPolicy parameter when calling a PowerShell script from a Linux distro (Ubuntu?) and I would assume that this would extrapolate out to MacOS due to the UNIX architecture.

From the looks of the comments that were added, this seems to have been fixed in Alpha Build 18. If this is still not working on MacOS with the latest build of PowerShell, I might suggest you report it on the PowerShell GitHub like this user did :)

Lurlenelurline answered 19/6, 2017 at 8:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.