dotnet-installer/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetConditions/EnvironmentAttribute.cs
Nate Amundson cd2b638b18 Trigger automated DockerHub builds
This change triggers automated DockerHub builds for successful
official Ubuntu builds of rel.1.0.0. The DockerHub repo for this is
https://hub.docker.com/r/microsoft/dotnet-preview/.

The variables DOCKER_HUB_REPO and DOCKER_HUB_TRIGGER_TOKEN are set in
the "DotNet-CLI-CI (Ubuntu) [rel.1.0.0]" VSTS build definition.

This change also allows the Environment TargetConditionAttribute to be
used to require that an environment variable is set, in addition to the
existing functionality of being able to be used to require that an
environment variable is equal to one of a set of specified values.
2016-03-16 14:39:02 -07:00

41 lines
1.2 KiB
C#

using System;
using System.Linq;
namespace Microsoft.DotNet.Cli.Build.Framework
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
public class EnvironmentAttribute : TargetConditionAttribute
{
private string _envVar;
private string[] _expectedVals;
public EnvironmentAttribute(string envVar, params string[] expectedVals)
{
if (string.IsNullOrEmpty(envVar))
{
throw new ArgumentNullException(nameof(envVar));
}
if (expectedVals == null)
{
throw new ArgumentNullException(nameof(expectedVals));
}
_envVar = envVar;
_expectedVals = expectedVals;
}
public override bool EvaluateCondition()
{
var actualVal = Environment.GetEnvironmentVariable(_envVar);
if (_expectedVals.Any())
{
return _expectedVals.Any(ev => string.Equals(actualVal, ev, StringComparison.Ordinal));
}
else
{
return !string.IsNullOrEmpty(actualVal);
}
}
}
}