Esempio n. 1
0
        internal void LoadEnviornmentVariables(IContinuousIntegrationServer continuousIntegrationServer)
        {
            var enviornmentVariables = new Dictionary <string, string>(continuousIntegrationServer.UserEnvironmentVariables);

            const string codecovName  = "CODECOV_ENV";
            var          codecovValue = EnviornmentVariable.GetEnviornmentVariable(codecovName);

            if (!string.IsNullOrWhiteSpace(codecovValue) && !enviornmentVariables.ContainsKey(codecovName))
            {
                enviornmentVariables[codecovName] = codecovValue;
            }

            var enviornmentVariableNames = Options.Envs;

            foreach (var enviornmentVariableName in enviornmentVariableNames)
            {
                if (enviornmentVariables.ContainsKey(enviornmentVariableName))
                {
                    continue;
                }

                var value = EnviornmentVariable.GetEnviornmentVariable(enviornmentVariableName);
                if (string.IsNullOrWhiteSpace(value))
                {
                    continue;
                }

                enviornmentVariables[enviornmentVariableName] = EnviornmentVariable.GetEnviornmentVariable(enviornmentVariableName);
            }

            UserEnvironmentVariables = enviornmentVariables;
        }
Esempio n. 2
0
        private static string LoadSlug()
        {
            var buildRepository = EnviornmentVariable.GetEnviornmentVariable("TEAMCITY_BUILD_REPOSITORY");

            if (string.IsNullOrWhiteSpace(buildRepository))
            {
                return(string.Empty);
            }

            var temp = buildRepository.Split(':');

            if (temp.Length > 0)
            {
                temp[0] = string.Empty;
            }

            buildRepository = string.Join(string.Empty, temp);

            var splitBuildRepository = buildRepository.Split('/');

            if (splitBuildRepository.Length > 1)
            {
                var repo  = splitBuildRepository[splitBuildRepository.Length - 1].Replace(".git", string.Empty);
                var owner = splitBuildRepository[splitBuildRepository.Length - 2];
                return($"{owner}/{repo}");
            }

            return(string.Empty);
        }
Esempio n. 3
0
        public void GetEnviornmentVariable_Should_Return_Empty_String_If_It_Does_Not_Exit()
        {
            // Given
            Environment.SetEnvironmentVariable("foo", null);

            // When
            var foo = EnviornmentVariable.GetEnviornmentVariable("foo");

            // Then
            foo.Should().BeEmpty();
        }
Esempio n. 4
0
        public void GetEnviornmentVariable_Should_Return_EnviornmentVariable_If_It_Exits()
        {
            // Given
            Environment.SetEnvironmentVariable("foo", "bar");

            // When
            var foo = EnviornmentVariable.GetEnviornmentVariable("foo");

            // Then
            foo.Should().Be("bar");
        }
Esempio n. 5
0
        public void GetFirstExistingEnvironmentVariable_Should_Return_Second_Value_If_First_Doesnt_Exist()
        {
            // Given
            Environment.SetEnvironmentVariable("bar", "barValue");

            // When
            var foo = EnviornmentVariable.GetFirstExistingEnvironmentVariable("foo", "bar");

            // Then
            foo.Should().Be("barValue");
        }
Esempio n. 6
0
        private static string LoadBranch()
        {
            var pullRequestBranch = EnviornmentVariable.GetEnviornmentVariable("SYSTEM_PULLREQUEST_TARGETBRANCH");

            if (!string.IsNullOrEmpty(pullRequestBranch))
            {
                return(pullRequestBranch);
            }

            return(EnviornmentVariable.GetEnviornmentVariable("BUILD_SOURCEBRANCHNAME"));
        }
Esempio n. 7
0
        public void GetFirstExistingEnvironmentVariable_Should_Return_Empty_String_If_None_Exist()
        {
            // Given
            Environment.SetEnvironmentVariable("foo", null);
            Environment.SetEnvironmentVariable("bar", null);

            // When
            var foo = EnviornmentVariable.GetFirstExistingEnvironmentVariable("foo", "bar");

            // Then
            foo.Should().BeEmpty();
        }
Esempio n. 8
0
        private static bool LoadDetecter()
        {
            var appVeyor = EnviornmentVariable.GetEnviornmentVariable("APPVEYOR");
            var ci       = EnviornmentVariable.GetEnviornmentVariable("CI");

            if (string.IsNullOrWhiteSpace(appVeyor) || string.IsNullOrWhiteSpace(ci))
            {
                return(false);
            }

            return(appVeyor.Equals("True") && ci.Equals("True"));
        }
Esempio n. 9
0
        private static bool LoadDetecter()
        {
            var appVeyor = EnviornmentVariable.GetEnviornmentVariable("APPVEYOR");
            var ci       = EnviornmentVariable.GetEnviornmentVariable("CI");

            if (string.IsNullOrWhiteSpace(appVeyor) || string.IsNullOrWhiteSpace(ci))
            {
                return(false);
            }

            return(appVeyor.Equals(ci, StringComparison.Ordinal) &&
                   appVeyor.Equals("True", StringComparison.OrdinalIgnoreCase));
        }
Esempio n. 10
0
        private static string LoadJob()
        {
            var slug    = EnviornmentVariable.GetEnviornmentVariable("BUILD_REPOSITORY_NAME");
            var version = EnviornmentVariable.GetEnviornmentVariable("BUILD_BUILDNUMBER");

            if (string.IsNullOrEmpty(slug) || string.IsNullOrEmpty(version))
            {
                return(string.Empty);
            }

            var job = $"{slug}/{version}";

            return(job);
        }
Esempio n. 11
0
        private static string LoadJob()
        {
            var accountName = EnviornmentVariable.GetEnviornmentVariable("APPVEYOR_ACCOUNT_NAME");
            var slug        = EnviornmentVariable.GetEnviornmentVariable("APPVEYOR_PROJECT_SLUG");
            var version     = EnviornmentVariable.GetEnviornmentVariable("APPVEYOR_BUILD_VERSION");

            if (string.IsNullOrWhiteSpace(accountName) || string.IsNullOrWhiteSpace(slug) || string.IsNullOrWhiteSpace(version))
            {
                return(string.Empty);
            }

            var job = $"{accountName}/{slug}/{version}";

            return(job);
        }
Esempio n. 12
0
        private static string LoadBuildUrl()
        {
            var hostUrl     = EnviornmentVariable.GetEnviornmentVariable("APPVEYOR_URL");
            var accountName = EnviornmentVariable.GetEnviornmentVariable("APPVEYOR_ACCOUNT_NAME");
            var slug        = EnviornmentVariable.GetEnviornmentVariable("APPVEYOR_PROJECT_SLUG");
            var jobId       = EnviornmentVariable.GetEnviornmentVariable("APPVEYOR_JOB_ID");

            if (IsNullOrEmpty(hostUrl, accountName, slug, jobId) || !Uri.TryCreate(hostUrl, UriKind.Absolute, out var uri) || (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps))
            {
                return(string.Empty);
            }

            var jobUrl = $"{hostUrl}/project/{accountName}/{slug}/build/job/{jobId}";

            return(jobUrl);
        }
Esempio n. 13
0
        protected static bool CheckEnvironmentVariables(params string[] environmentVariables)
        {
            var foundVariables = new List <string>();

            foreach (var variable in environmentVariables)
            {
                var ci = EnviornmentVariable.GetEnviornmentVariable(variable);

                if (string.IsNullOrWhiteSpace(ci) || !ci.Equals("True", StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }

                foundVariables.Add(ci);
            }

            var firstValue = foundVariables.FirstOrDefault();

            return(!string.IsNullOrEmpty(firstValue) && foundVariables.Skip(1).All(v => v.Equals(firstValue, StringComparison.Ordinal)));
        }
Esempio n. 14
0
        private static string LoadCommit()
        {
            var commit = EnviornmentVariable.GetEnviornmentVariable("TEAMCITY_BUILD_COMMIT");

            return(!string.IsNullOrWhiteSpace(commit) ? commit : EnviornmentVariable.GetEnviornmentVariable("BUILD_VCS_NUMBER"));
        }
Esempio n. 15
0
        private static string LoadBuild()
        {
            var build = EnviornmentVariable.GetEnviornmentVariable("BUILD_BUILDNUMBER");

            return(!string.IsNullOrWhiteSpace(build) ? Uri.EscapeDataString(build) : string.Empty);
        }
Esempio n. 16
0
        private static string LoadBranch()
        {
            var branch = EnviornmentVariable.GetEnviornmentVariable("GITHUB_REF");

            return(string.IsNullOrWhiteSpace(branch) ? string.Empty : branch.StartsWith("ref/heads/") ? branch.Substring(10) : branch);
        }
Esempio n. 17
0
        private static string LoadBuild()
        {
            var build = EnviornmentVariable.GetEnviornmentVariable("APPVEYOR_JOB_ID");

            return(!string.IsNullOrWhiteSpace(build) ? Uri.EscapeDataString(build) : string.Empty);
        }
Esempio n. 18
0
        private static bool LoadDetecter()
        {
            var tfbuild = EnviornmentVariable.GetEnviornmentVariable("TF_BUILD");

            return(tfbuild.Equals("True", StringComparison.OrdinalIgnoreCase));
        }
Esempio n. 19
0
        private static bool LoadDetecter()
        {
            var teamCity = EnviornmentVariable.GetEnviornmentVariable("TEAMCITY_VERSION");

            return(!string.IsNullOrWhiteSpace(teamCity));
        }
Esempio n. 20
0
        private static string LoadBuildUrl()
        {
            var buildUrl = EnviornmentVariable.GetEnviornmentVariable("TEAMCITY_BUILD_URL");

            return(!string.IsNullOrWhiteSpace(buildUrl) ? Uri.EscapeDataString(buildUrl) : string.Empty);
        }