cake icon indicating copy to clipboard operation
cake copied to clipboard

VSTS IsHostedAgent detection is flawed

Open trailmax opened this issue 7 years ago • 6 comments

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 avatar Jul 14 '17 14:07 trailmax

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.

trailmax avatar Jul 14 '17 14:07 trailmax

Related to #1580.

patriksvensson avatar Jul 14 '17 15:07 patriksvensson

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

agc93 avatar Jul 26 '17 07:07 agc93

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

charlessolar avatar Dec 04 '17 13:12 charlessolar

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"));

kevbite avatar Jun 15 '18 16:06 kevbite

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

augustoproiete avatar Oct 12 '21 01:10 augustoproiete