spatialguy
spatialguy

Reputation: 474

Run powershell build step in VSTS agent installed on mac?

I installed VSTS build agent on mac to build xamarin iOS project. Builds worked fine until I added powershell build step. Even though I installed powershell for mac (https://github.com/PowerShell/PowerShell) and re-installed the agent, VSTS complains it does not have agent that is capable to run the build.

No agent could be found with the following capabilities: DotNetFramework, Xamarin.iOS, npm

When I disable the build step, builds work just fine.

Is it possible to run powershell build step on Mac?

Upvotes: 1

Views: 1894

Answers (6)

Antoine Robin
Antoine Robin

Reputation: 198

Things seem to have moved forward because I ran successfully today a PowerShell@2 task on a Mac Self-Hosted Agent from an Azure DevOps build pipeline.

By checking "Enable system diagnostics" when queuing the build, the log shows me that the task found itself the path to the PowerShell Core (pwsh) that I installed on my Mac with the help of Homebrew (brew cask install powershell - see https://learn.microsoft.com/fr-fr/powershell/scripting/install/installing-powershell-core-on-macos).

Upvotes: 0

Jarrod L
Jarrod L

Reputation: 293

This is a follow-up to the accepted answer to address a question in a comment which I also had.

Thanks to spatialguy for posting and finding a simple solution to this problem. I had the same problem as KeithA45:

QUESTION: What if you wanted to do the same, but also pass arguments to the Bash script which passes them to the Powershell script?

I found a solution to this, first off, I modified the shell script task to include the Visual Studio Team Services (VSTS) environmental variables that I wanted to pass to the powershell script.

enter image description here

Next, I pass the arguments through to the called powershell script by slightly modifying the shell script mentioned by the accepted answer.

#!/bin/bash
powershell ./Version.ps1 $1 $2

Finally, in the powershell script, I catch the arguments that have been passed through using using param like this:

param([string]$version, [string]$path)

Wherein I can now use the variables $version and $path which contain the original arguments entered in VSTS to the needs of my powershell script.

Upvotes: 0

Palanivelu Samudi
Palanivelu Samudi

Reputation: 1225

In TFS build go to Agents Queues=>Capablilities=>Add variable named as DotNetFramework and give value for mac agent's dotnet framework path.

enter image description here It's fix for the issue "No agent could be found with the following capabilities:DotNetFramework"

Upvotes: 0

spatialguy
spatialguy

Reputation: 474

As MrHinsh clarified, the PowerShell task cannot be used on Mac.

As a workaround I used ShellScript task:

ShellScript task

With the following bash script:

#!/bin/bash
powershell ./SetAppVersion.ps1

Also, the powershell installer did not seem to add powershell to my PATH so I had to add it:

$ export PATH=$PATH:/usr/local/microsoft/powershell/6.0.0-alpha.16

Upvotes: 4

No, you can't use a PowerShell task on a Mac, only node tasks are supported.

PowerShell tasks as currently written in PowerShell3 which is not supported on Mac. You can request that the team implement this on http://visualstudio.uservoice.com

Upvotes: 1

Chris Gardner
Chris Gardner

Reputation: 71

If you're sure that DotNetFramework is installed then you can go to the Agent Queues settings and add a custom Capability to it called exactly that.

That should allow it to run but it might fail after that if the agent can't actually find them, but it might also succeed so it's probably worth a try.

Upvotes: 1

Related Questions