Sets timestamp as default runID when environment variable is not set.

This commit is contained in:
benbierens 2023-09-27 08:49:36 +02:00
parent 42b0ab67a0
commit d830ccb48e
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
1 changed files with 6 additions and 4 deletions

View File

@ -37,18 +37,20 @@ namespace DistTestCore
public static string GetTestId()
{
return GetEnvVar("TESTID");
return GetEnvVar("TESTID", "EnvVar-TESTID-NotSet");
}
public static string GetRunId()
{
return GetEnvVar("RUNID");
var now = DateTime.UtcNow;
var defaultValue = now.ToString("yyyyMMdd-hhmmss");
return GetEnvVar("RUNID", defaultValue);
}
private static string GetEnvVar(string name)
private static string GetEnvVar(string name, string defaultValue)
{
var v = Environment.GetEnvironmentVariable(name);
if (string.IsNullOrEmpty(v)) return $"EnvVar-{name}-NotSet";
if (string.IsNullOrEmpty(v)) return defaultValue;
return v;
}