cake-build / cake

:cake: Cake (C# Make) is a cross platform build automation system.
https://cakebuild.net
MIT License
3.88k stars 726 forks source link

VSTS IsHostedAgent detection is flawed #1684

Open trailmax opened 7 years ago

trailmax commented 7 years ago

When running CakeBuild in VSTS and rely on Context.TFBuild().IsRunningOnVSTS. However we have 2 hosted build agents and second build agent is called "Hosted Agent 2". And build is always failing on the second agent.

Here code insists that agent name is exactly "Hosted Agent".

Also We are setting up private build agent and this code does not agree with private build agents. It is still VSTS build, only not run in hosted agent.

I propose to change the check for the agent name to .StartsWith("Hosted Agent") and remove check for IsHostedAgent from IsRunningOnVSTS option.

@agc93 what do you think? (as far as I remember you have done work on this)

I can do PR for this.

trailmax commented 7 years ago

Looking on my VSTS, my other hosted agent is called "Hosted VS2017 2". So we can't rely on this value to be anything consistent.

patriksvensson commented 7 years ago

Related to #1580.

agc93 commented 7 years ago

Yep, I'll have a look at this (a few different parts of the logic need improvements)

charlessolar commented 6 years ago

Just ran into this issue - only need to know if its building on VSTS so now I'm doing var isVSTS = buildSystem.TFBuild.IsRunningOnVSTS || buildSystem.TFBuild.IsRunningOnTFS; instead of just IsRunningOnVSTS

kevbite commented 6 years ago

We've just stumbled across this issue too since we've added a couple more hosted agents to our team. As a workaround we're just checking that we've got a agent name:

var isRunningOnVSTS = !string.IsNullOrEmpty(EnvironmentVariable("AGENT_NAME"));
augustoproiete commented 2 years ago

@agc93 / @pascalberger Has this been resolved by 8d3483b?