-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2385: TeamCity logger uses wrong flowId
- Loading branch information
1 parent
da319e0
commit 2dba64b
Showing
17 changed files
with
498 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,57 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
static class EnvironmentHelper | ||
{ | ||
static readonly Lazy<bool> isMono = new Lazy<bool>(() => Type.GetType("Mono.Runtime") != null); | ||
static readonly string[] reporterEnvironmentVariables = | ||
{ | ||
// AppVeyorReporter | ||
"APPVEYOR_API_URL", | ||
// TeamCityReporter | ||
"TEAMCITY_PROJECT_NAME", | ||
"TEAMCITY_PROCESS_FLOW_ID", | ||
// VstsReporter | ||
"VSTS_ACCESS_TOKEN", | ||
"SYSTEM_TEAMFOUNDATIONCOLLECTIONURI", | ||
"SYSTEM_TEAMPROJECT", | ||
"BUILD_BUILDID", | ||
}; | ||
|
||
/// <summary> | ||
/// Returns <c>true</c> if you're currently running in Mono; <c>false</c> if you're running in .NET Framework. | ||
/// </summary> | ||
public static bool IsMono => isMono.Value; | ||
|
||
public static IDisposable NullifyEnvironmentalReporters() | ||
{ | ||
var result = new EnvironmentRestorer(reporterEnvironmentVariables); | ||
|
||
foreach (var variable in reporterEnvironmentVariables) | ||
Environment.SetEnvironmentVariable(variable, null); | ||
|
||
return result; | ||
} | ||
|
||
public static IDisposable RestoreEnvironment(params string[] variables) => | ||
new EnvironmentRestorer(variables); | ||
|
||
class EnvironmentRestorer : IDisposable | ||
{ | ||
Dictionary<string, string?> savedVariables = new(); | ||
|
||
public EnvironmentRestorer(string[] variables) | ||
{ | ||
foreach (var variable in variables) | ||
savedVariables[variable] = Environment.GetEnvironmentVariable(variable); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
foreach (var kvp in savedVariables) | ||
Environment.SetEnvironmentVariable(kvp.Key, kvp.Value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.