Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 356
Ciaran Donoghue Avatar asked Nov 28 '16 15:11

Ciaran Donoghue


1 Answers

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 :)

like image 134
Fredulom Avatar answered Nov 07 '22 07:11

Fredulom