コード例 #1
0
        private static void SetupGitlabEnvironment()
        {
            IsCI       = true;
            Provider   = "gitlab";
            Repository = EnvironmentHelpers.GetEnvironmentVariable("CI_REPOSITORY_URL");
            Commit     = EnvironmentHelpers.GetEnvironmentVariable("CI_COMMIT_SHA");
            Branch     = EnvironmentHelpers.GetEnvironmentVariable("CI_COMMIT_BRANCH");
            Tag        = EnvironmentHelpers.GetEnvironmentVariable("CI_COMMIT_TAG");
            if (string.IsNullOrWhiteSpace(Branch))
            {
                Branch = EnvironmentHelpers.GetEnvironmentVariable("CI_COMMIT_REF_NAME");
            }

            SourceRoot    = EnvironmentHelpers.GetEnvironmentVariable("CI_PROJECT_DIR");
            WorkspacePath = EnvironmentHelpers.GetEnvironmentVariable("CI_PROJECT_DIR");

            PipelineId     = EnvironmentHelpers.GetEnvironmentVariable("CI_PIPELINE_ID");
            PipelineName   = EnvironmentHelpers.GetEnvironmentVariable("CI_PROJECT_PATH");
            PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("CI_PIPELINE_IID");
            PipelineUrl    = EnvironmentHelpers.GetEnvironmentVariable("CI_PIPELINE_URL");

            JobUrl    = EnvironmentHelpers.GetEnvironmentVariable("CI_JOB_URL");
            JobName   = EnvironmentHelpers.GetEnvironmentVariable("CI_JOB_NAME");
            StageName = EnvironmentHelpers.GetEnvironmentVariable("CI_JOB_STAGE");

            // Clean pipeline url
            PipelineUrl = PipelineUrl?.Replace("/-/pipelines/", "/pipelines/");
        }
        private static void StartProcesses()
        {
            if (AzureAppServices.Metadata.DebugModeEnabled)
            {
                const string ddLogLevelKey = "DD_LOG_LEVEL";
                if (EnvironmentHelpers.GetEnvironmentVariable(ddLogLevelKey) == null)
                {
                    // This ensures that a single setting from applicationConfig can enable debug logs for every aspect of the extension
                    EnvironmentHelpers.SetEnvironmentVariable(ddLogLevelKey, "debug");
                }
            }

            foreach (var metadata in Processes)
            {
                if (!string.IsNullOrWhiteSpace(metadata.ProcessPath))
                {
                    if (!metadata.IsBeingManaged)
                    {
                        metadata.KeepAliveTask = StartProcessWithKeepAlive(metadata);
                    }
                }
                else
                {
                    Log.Debug("There is no path configured for {ProcessName}.", metadata.Name);
                }
            }
        }
コード例 #3
0
        private static void SetupAppveyorEnvironment()
        {
            IsCI     = true;
            Provider = "appveyor";
            string repoProvider = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_REPO_PROVIDER");

            if (repoProvider == "github")
            {
                Repository = string.Format("https://github.com/{0}.git", EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_REPO_NAME"));
            }
            else
            {
                Repository = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_REPO_NAME");
            }

            Commit         = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_REPO_COMMIT");
            SourceRoot     = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_BUILD_FOLDER");
            WorkspacePath  = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_BUILD_FOLDER");
            PipelineId     = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_BUILD_ID");
            PipelineName   = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_REPO_NAME");
            PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_BUILD_NUMBER");
            PipelineUrl    = string.Format("https://ci.appveyor.com/project/{0}/builds/{1}", EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_REPO_NAME"), EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_BUILD_ID"));
            JobUrl         = PipelineUrl;
            Branch         = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH");
            Tag            = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_REPO_TAG_NAME");
            if (string.IsNullOrWhiteSpace(Branch))
            {
                Branch = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_REPO_BRANCH");
            }
        }
コード例 #4
0
        public void Refresh()
        {
            var rawValue = EnvironmentHelpers.GetEnvironmentVariable(EnvironmentVariableName);
            var value    = JsonConvert.DeserializeObject <PerformanceCountersValue>(rawValue);

            _statsd.Gauge(MetricsNames.Gen0HeapSize, value.Gen0Size);
            _statsd.Gauge(MetricsNames.Gen1HeapSize, value.Gen1Size);
            _statsd.Gauge(MetricsNames.Gen2HeapSize, value.Gen2Size);
            _statsd.Gauge(MetricsNames.LohSize, value.LohSize);

            var gen0 = GC.CollectionCount(0);
            var gen1 = GC.CollectionCount(1);
            var gen2 = GC.CollectionCount(2);

            if (_previousGen0Count != null)
            {
                _statsd.Increment(MetricsNames.Gen0CollectionsCount, gen0 - _previousGen0Count.Value);
            }

            if (_previousGen1Count != null)
            {
                _statsd.Increment(MetricsNames.Gen1CollectionsCount, gen1 - _previousGen1Count.Value);
            }

            if (_previousGen2Count != null)
            {
                _statsd.Increment(MetricsNames.Gen2CollectionsCount, gen2 - _previousGen2Count.Value);
            }

            _previousGen0Count = gen0;
            _previousGen1Count = gen1;
            _previousGen2Count = gen2;

            Log.Debug("Sent the following metrics: {metrics}", GarbageCollectionMetrics);
        }
コード例 #5
0
        private static void SetupGithubActionsEnvironment()
        {
            IsCI       = true;
            Provider   = "github";
            Repository = string.Format("https://github.com/{0}.git", EnvironmentHelpers.GetEnvironmentVariable("GITHUB_REPOSITORY"));
            Commit     = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_SHA");

            string headRef = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_HEAD_REF");
            string ghRef   = !string.IsNullOrEmpty(headRef) ? headRef : EnvironmentHelpers.GetEnvironmentVariable("GITHUB_REF");

            if (ghRef.Contains("tags"))
            {
                Tag = ghRef;
            }
            else
            {
                Branch = ghRef;
            }

            SourceRoot     = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_WORKSPACE");
            WorkspacePath  = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_WORKSPACE");
            PipelineId     = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_RUN_ID");
            PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_RUN_NUMBER");
            PipelineName   = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_WORKFLOW");
            PipelineUrl    = $"https://github.com/{EnvironmentHelpers.GetEnvironmentVariable("GITHUB_REPOSITORY")}/commit/{Commit}/checks";
            JobUrl         = PipelineUrl;
        }
コード例 #6
0
        private static void SetupTravisEnvironment()
        {
            IsCI     = true;
            Provider = "travisci";

            string prSlug   = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_PULL_REQUEST_SLUG");
            string repoSlug = !string.IsNullOrEmpty(prSlug) ? prSlug : EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_REPO_SLUG");

            Repository = string.Format("https://github.com/{0}.git", repoSlug);
            Commit     = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_COMMIT");
            Tag        = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_TAG");
            if (string.IsNullOrEmpty(Tag))
            {
                Branch = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_PULL_REQUEST_BRANCH");
                if (string.IsNullOrWhiteSpace(Branch))
                {
                    Branch = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_BRANCH");
                }
            }

            SourceRoot     = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_BUILD_DIR");
            WorkspacePath  = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_BUILD_DIR");
            PipelineId     = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_BUILD_ID");
            PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_BUILD_NUMBER");
            PipelineName   = repoSlug;
            PipelineUrl    = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_BUILD_WEB_URL");
            JobUrl         = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_JOB_WEB_URL");
        }
コード例 #7
0
 public ProfilerStatus()
 {
     _isProfilingEnabled = EnvironmentHelpers.GetEnvironmentVariable(ConfigurationKeys.ProfilingEnabled)?.ToBoolean() ?? false;
     Log.Information("Continuous Profiler is {IsEnabled}.", _isProfilingEnabled ? "enabled" : "disabled");
     _lockObj       = new();
     _isInitialized = false;
 }
コード例 #8
0
 static MethodBuilder()
 {
     ForceMdTokenLookup = bool.TryParse(EnvironmentHelpers.GetEnvironmentVariable(ConfigurationKeys.Debug.ForceMdTokenLookup), out bool result)
             ? result
             : false;
     ForceFallbackLookup = bool.TryParse(EnvironmentHelpers.GetEnvironmentVariable(ConfigurationKeys.Debug.ForceFallbackLookup), out result)
             ? result && !ForceMdTokenLookup
             : false;
 }
コード例 #9
0
        private static string GetLogDirectory()
        {
            var    nativeLogFile = EnvironmentHelpers.GetEnvironmentVariable(ConfigurationKeys.ProfilerLogPath);
            string logDirectory  = null;

            if (!string.IsNullOrEmpty(nativeLogFile))
            {
                logDirectory = Path.GetDirectoryName(nativeLogFile);
            }

            // This entire block may throw a SecurityException if not granted the System.Security.Permissions.FileIOPermission
            // because of the following API calls
            //   - Directory.Exists
            //   - Environment.GetFolderPath
            //   - Path.GetTempPath
            if (logDirectory == null)
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    var windowsDefaultDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Datadog .NET Tracer", "logs");
                    if (Directory.Exists(windowsDefaultDirectory))
                    {
                        logDirectory = windowsDefaultDirectory;
                    }
                }
                else
                {
                    // Linux
                    if (Directory.Exists(NixDefaultDirectory))
                    {
                        logDirectory = NixDefaultDirectory;
                    }
                    else
                    {
                        try
                        {
                            var di = Directory.CreateDirectory(NixDefaultDirectory);
                            logDirectory = NixDefaultDirectory;
                        }
                        catch
                        {
                            // Unable to create the directory meaning that the user
                            // will have to create it on their own.
                        }
                    }
                }
            }

            if (logDirectory == null)
            {
                // Last effort at writing logs
                logDirectory = Path.GetTempPath();
            }

            return(logDirectory);
        }
コード例 #10
0
        private static string GetLogDirectory()
        {
            string logDirectory = EnvironmentHelpers.GetEnvironmentVariable(ConfigurationKeys.LogDirectory);

            if (logDirectory == null)
            {
#pragma warning disable 618 // ProfilerLogPath is deprecated but still supported
                var nativeLogFile = EnvironmentHelpers.GetEnvironmentVariable(ConfigurationKeys.ProfilerLogPath);
#pragma warning restore 618

                if (!string.IsNullOrEmpty(nativeLogFile))
                {
                    logDirectory = Path.GetDirectoryName(nativeLogFile);
                }
            }

            // This entire block may throw a SecurityException if not granted the System.Security.Permissions.FileIOPermission
            // because of the following API calls
            //   - Directory.Exists
            //   - Environment.GetFolderPath
            //   - Path.GetTempPath
            if (logDirectory == null)
            {
#if NETFRAMEWORK
                logDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Datadog .NET Tracer", "logs");
#else
                if (RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
                {
                    logDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Datadog .NET Tracer", "logs");
                }
                else
                {
                    // Linux
                    logDirectory = "/var/log/datadog/dotnet";
                }
#endif
            }

            if (!Directory.Exists(logDirectory))
            {
                try
                {
                    Directory.CreateDirectory(logDirectory);
                }
                catch
                {
                    // Unable to create the directory meaning that the user
                    // will have to create it on their own.
                    // Last effort at writing logs
                    logDirectory = Path.GetTempPath();
                }
            }

            return(logDirectory);
        }
コード例 #11
0
        /// <summary>
        /// Invoked by the loader
        /// </summary>
        public static void Initialize()
        {
            try
            {
                if (DomainMetadata.Instance.ShouldAvoidAppDomain())
                {
                    Log.Information("Skipping process manager initialization for AppDomain: {AppDomain}", DomainMetadata.Instance.AppDomainName);
                    return;
                }

                var automaticTraceEnabled = EnvironmentHelpers.GetEnvironmentVariable(ConfigurationKeys.TraceEnabled, string.Empty)?.ToBoolean() ?? true;

                if (AzureAppServices.Metadata.CustomTracingEnabled || automaticTraceEnabled)
                {
                    if (string.IsNullOrWhiteSpace(TraceAgentMetadata.ProcessPath))
                    {
                        Log.Warning("Requested to start the Trace Agent but the process path hasn't been supplied in environment.");
                    }
                    else if (!Directory.Exists(TraceAgentMetadata.DirectoryPath))
                    {
                        Log.Warning("Directory for trace agent does not exist: {Directory}. The process won't be started.", TraceAgentMetadata.DirectoryPath);
                    }
                    else
                    {
                        Processes.Add(TraceAgentMetadata);
                    }
                }

                if (AzureAppServices.Metadata.NeedsDogStatsD || automaticTraceEnabled)
                {
                    if (string.IsNullOrWhiteSpace(DogStatsDMetadata.ProcessPath))
                    {
                        Log.Warning("Requested to start dogstatsd but the process path hasn't been supplied in environment.");
                    }
                    else if (!Directory.Exists(DogStatsDMetadata.DirectoryPath))
                    {
                        Log.Warning("Directory for dogstatsd does not exist: {Directory}. The process won't be started.", DogStatsDMetadata.DirectoryPath);
                    }
                    else
                    {
                        Processes.Add(DogStatsDMetadata);
                    }
                }

                if (Processes.Count > 0)
                {
                    Log.Debug("Starting {Count} child processes from process {ProcessName}, AppDomain {AppDomain}.", Processes.Count, DomainMetadata.Instance.ProcessName, DomainMetadata.Instance.AppDomainName);
                    StartProcesses();
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error when attempting to initialize process manager.");
            }
        }
コード例 #12
0
 private static void SetupBitbucketEnvironment()
 {
     IsCI           = true;
     Provider       = "bitbucketpipelines";
     Repository     = EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_GIT_SSH_ORIGIN");
     Commit         = EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_COMMIT");
     SourceRoot     = EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_CLONE_DIR");
     PipelineId     = EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_PIPELINE_UUID");
     PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_BUILD_NUMBER");
     PipelineUrl    = null;
 }
コード例 #13
0
 public HomeController(ILogger <HomeController> logger)
 {
     _logger       = logger;
     _hashId       = new Hashids();
     UrlPrefix     = EnvironmentHelpers.GetEnvironmentVariable("URL_PREFIX");
     AdminPassword = EnvironmentHelpers.GetEnvironmentVariable("ADMIN_PASSWORD");
     if (!Directory.Exists("persistence"))
     {
         Directory.CreateDirectory("persistence");
     }
 }
コード例 #14
0
    public void EnvironmentHelpersTests_GetEnvironmentVariable(string?process, string?user, string?machine, string expected)
    {
        // Arrange
        ConfigureEnvironmentVariableGetter(process, user, machine);

        // Act
        var actual = EnvironmentHelpers.GetEnvironmentVariable("jlhdfprtljedhfrptaejldhfprt");

        // Assert
        Assert.Equal(expected, actual);
    }
コード例 #15
0
        private static string GetEnvironmentVariableIfIsNotEmpty(string key, string defaultValue)
        {
            string value = EnvironmentHelpers.GetEnvironmentVariable(key, defaultValue);

            if (string.IsNullOrEmpty(value))
            {
                return(defaultValue);
            }

            return(value);
        }
コード例 #16
0
 private static void SetupBuildkiteEnvironment()
 {
     IsCI           = true;
     Provider       = "buildkite";
     Repository     = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_REPO");
     Commit         = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_COMMIT");
     SourceRoot     = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_BUILD_CHECKOUT_PATH");
     PipelineId     = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_BUILD_ID");
     PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_BUILD_NUMBER");
     PipelineUrl    = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_BUILD_URL");
     Branch         = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_BRANCH");
 }
コード例 #17
0
 private static void SetupGithubActionsEnvironment()
 {
     IsCI           = true;
     Provider       = "github";
     Repository     = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_REPOSITORY");
     Commit         = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_SHA");
     SourceRoot     = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_WORKSPACE");
     PipelineId     = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_RUN_ID");
     PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_RUN_NUMBER");
     PipelineUrl    = $"{Repository}/commit/{Commit}/checks";
     Branch         = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_REF");
 }
コード例 #18
0
 private static void SetupCircleCiEnvironment()
 {
     IsCI           = true;
     Provider       = "circleci";
     Repository     = EnvironmentHelpers.GetEnvironmentVariable("CIRCLE_REPOSITORY_URL");
     Commit         = EnvironmentHelpers.GetEnvironmentVariable("CIRCLE_SHA1");
     SourceRoot     = EnvironmentHelpers.GetEnvironmentVariable("CIRCLE_WORKING_DIRECTORY");
     PipelineId     = null;
     PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("CIRCLE_BUILD_NUM");
     PipelineUrl    = EnvironmentHelpers.GetEnvironmentVariable("CIRCLE_BUILD_URL");
     Branch         = EnvironmentHelpers.GetEnvironmentVariable("CIRCLE_BRANCH");
 }
コード例 #19
0
        private static int GetRateLimit()
        {
            string rawRateLimit = EnvironmentHelpers.GetEnvironmentVariable(ConfigurationKeys.LogRateLimit);

            if (!string.IsNullOrEmpty(rawRateLimit) &&
                int.TryParse(rawRateLimit, out var rate) &&
                (rate >= 0))
            {
                return(rate);
            }

            return(DefaultLogMessageRateLimit);
        }
コード例 #20
0
        internal static NativeCallTargetDefinition[] GetServerlessDefinitions()
        {
            try
            {
                LambdaHandler handler      = new LambdaHandler(EnvironmentHelpers.GetEnvironmentVariable(HandlerEnvName));
                var           assemblyName = typeof(InstrumentationDefinitions).Assembly.FullName;
                var           paramCount   = handler.ParamTypeArray.Length;

                var integrationType = GetIntegrationType(handler.ParamTypeArray[0], paramCount);
                return(new NativeCallTargetDefinition[]
                {
                    new(handler.GetAssembly(), handler.GetFullType(), handler.GetMethodName(), handler.ParamTypeArray, 0, 0, 0, 65535, 65535, 65535, assemblyName, integrationType)
                });
            }
コード例 #21
0
 private static void SetupBuildkiteEnvironment()
 {
     IsCI           = true;
     Provider       = "buildkite";
     Repository     = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_REPO");
     Commit         = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_COMMIT");
     Branch         = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_BRANCH");
     Tag            = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_TAG");
     SourceRoot     = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_BUILD_CHECKOUT_PATH");
     WorkspacePath  = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_BUILD_CHECKOUT_PATH");
     PipelineId     = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_BUILD_ID");
     PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_BUILD_NUMBER");
     PipelineName   = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_PIPELINE_SLUG");
     PipelineUrl    = EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_BUILD_URL");
     JobUrl         = string.Format("{0}#{1}", EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_BUILD_URL"), EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE_JOB_ID"));
 }
コード例 #22
0
 private static void SetupAppveyorEnvironment()
 {
     IsCI           = true;
     Provider       = "appveyor";
     Repository     = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_REPO_NAME");
     Commit         = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_REPO_COMMIT");
     SourceRoot     = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_BUILD_FOLDER");
     PipelineId     = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_BUILD_ID");
     PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_BUILD_NUMBER");
     PipelineUrl    = string.Format("https://ci.appveyor.com/project/{0}/builds/{1}", EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_PROJECT_SLUG"), EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_BUILD_ID"));
     Branch         = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH");
     if (string.IsNullOrWhiteSpace(Branch))
     {
         Branch = EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR_REPO_BRANCH");
     }
 }
コード例 #23
0
        private static DateTimeOffset?GetDateTimeOffsetEnvironmentVariableIfIsNotEmpty(string key, DateTimeOffset?defaultValue)
        {
            string value = EnvironmentHelpers.GetEnvironmentVariable(key);

            if (string.IsNullOrEmpty(value))
            {
                return(defaultValue);
            }

            if (DateTimeOffset.TryParseExact(value, "yyyy-MM-ddTHH:mm:sszzz", CultureInfo.InvariantCulture, DateTimeStyles.None, out var valueDateTimeOffset))
            {
                return(valueDateTimeOffset);
            }

            return(defaultValue);
        }
コード例 #24
0
        private void SetupGithubActionsEnvironment()
        {
            IsCI     = true;
            Provider = "github";

            var serverUrl = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_SERVER_URL");

            if (string.IsNullOrWhiteSpace(serverUrl))
            {
                serverUrl = "https://github.com";
            }

            var rawRepository = $"{serverUrl}/{EnvironmentHelpers.GetEnvironmentVariable("GITHUB_REPOSITORY")}";

            Repository = $"{rawRepository}.git";
            Commit     = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_SHA");

            string headRef = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_HEAD_REF");
            string ghRef   = !string.IsNullOrEmpty(headRef) ? headRef : EnvironmentHelpers.GetEnvironmentVariable("GITHUB_REF");

            if (ghRef?.Contains("tags") == true)
            {
                Tag = ghRef;
            }
            else
            {
                Branch = ghRef;
            }

            SourceRoot     = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_WORKSPACE");
            WorkspacePath  = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_WORKSPACE");
            PipelineId     = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_RUN_ID");
            PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_RUN_NUMBER");
            PipelineName   = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_WORKFLOW");
            var attempts = EnvironmentHelpers.GetEnvironmentVariable("GITHUB_RUN_ATTEMPT");

            if (string.IsNullOrWhiteSpace(attempts))
            {
                PipelineUrl = $"{rawRepository}/actions/runs/{PipelineId}";
            }
            else
            {
                PipelineUrl = $"{rawRepository}/actions/runs/{PipelineId}/attempts/{attempts}";
            }

            JobUrl = $"{serverUrl}/{EnvironmentHelpers.GetEnvironmentVariable("GITHUB_REPOSITORY")}/commit/{Commit}/checks";
        }
コード例 #25
0
        private void SetupAzurePipelinesEnvironment()
        {
            IsCI           = true;
            Provider       = "azurepipelines";
            SourceRoot     = EnvironmentHelpers.GetEnvironmentVariable("BUILD_SOURCESDIRECTORY");
            WorkspacePath  = EnvironmentHelpers.GetEnvironmentVariable("BUILD_SOURCESDIRECTORY");
            PipelineId     = EnvironmentHelpers.GetEnvironmentVariable("BUILD_BUILDID");
            PipelineName   = EnvironmentHelpers.GetEnvironmentVariable("BUILD_DEFINITIONNAME");
            PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("BUILD_BUILDID");
            PipelineUrl    = string.Format(
                "{0}{1}/_build/results?buildId={2}",
                EnvironmentHelpers.GetEnvironmentVariable("SYSTEM_TEAMFOUNDATIONSERVERURI"),
                EnvironmentHelpers.GetEnvironmentVariable("SYSTEM_TEAMPROJECTID"),
                EnvironmentHelpers.GetEnvironmentVariable("BUILD_BUILDID"));

            StageName = EnvironmentHelpers.GetEnvironmentVariable("SYSTEM_STAGEDISPLAYNAME");

            JobName = EnvironmentHelpers.GetEnvironmentVariable("SYSTEM_JOBDISPLAYNAME");
            JobUrl  = string.Format(
                "{0}{1}/_build/results?buildId={2}&view=logs&j={3}&t={4}",
                EnvironmentHelpers.GetEnvironmentVariable("SYSTEM_TEAMFOUNDATIONSERVERURI"),
                EnvironmentHelpers.GetEnvironmentVariable("SYSTEM_TEAMPROJECTID"),
                EnvironmentHelpers.GetEnvironmentVariable("BUILD_BUILDID"),
                EnvironmentHelpers.GetEnvironmentVariable("SYSTEM_JOBID"),
                EnvironmentHelpers.GetEnvironmentVariable("SYSTEM_TASKINSTANCEID"));

            string prRepo = EnvironmentHelpers.GetEnvironmentVariable("SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI");

            Repository = !string.IsNullOrWhiteSpace(prRepo) ? prRepo : EnvironmentHelpers.GetEnvironmentVariable("BUILD_REPOSITORY_URI");

            string prCommit = EnvironmentHelpers.GetEnvironmentVariable("SYSTEM_PULLREQUEST_SOURCECOMMITID");

            Commit = !string.IsNullOrWhiteSpace(prCommit) ? prCommit : EnvironmentHelpers.GetEnvironmentVariable("BUILD_SOURCEVERSION");

            string prBranch = EnvironmentHelpers.GetEnvironmentVariable("SYSTEM_PULLREQUEST_SOURCEBRANCH");

            Branch = !string.IsNullOrWhiteSpace(prBranch) ? prBranch : EnvironmentHelpers.GetEnvironmentVariable("BUILD_SOURCEBRANCH");

            if (string.IsNullOrWhiteSpace(Branch))
            {
                Branch = EnvironmentHelpers.GetEnvironmentVariable("BUILD_SOURCEBRANCHNAME");
            }

            Message     = EnvironmentHelpers.GetEnvironmentVariable("BUILD_SOURCEVERSIONMESSAGE");
            AuthorName  = EnvironmentHelpers.GetEnvironmentVariable("BUILD_REQUESTEDFORID");
            AuthorEmail = EnvironmentHelpers.GetEnvironmentVariable("BUILD_REQUESTEDFOREMAIL");
        }
コード例 #26
0
 private static void SetupTravisEnvironment()
 {
     IsCI           = true;
     Provider       = "travis";
     Repository     = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_REPO_SLUG");
     Commit         = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_COMMIT");
     SourceRoot     = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_BUILD_DIR");
     PipelineId     = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_BUILD_ID");
     PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_BUILD_NUMBER");
     PipelineUrl    = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_BUILD_WEB_URL");
     JobUrl         = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_JOB_WEB_URL");
     Branch         = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_PULL_REQUEST_BRANCH");
     if (string.IsNullOrWhiteSpace(Branch))
     {
         Branch = EnvironmentHelpers.GetEnvironmentVariable("TRAVIS_BRANCH");
     }
 }
コード例 #27
0
 /// <summary>
 /// Construct an instance of the membership storage system
 /// </summary>
 /// <param name="iTableStorageRootURLEnvironVarName">Root Azure table storage URL</param>
 /// <param name="iConnectionStringEnvironVarName">Environment variable name of the connection string to use</param>
 /// <param name="iFunctionName">The name of the function</param>
 public Storage(String iTableStorageRootURLEnvironVarName,
                String iConnectionStringEnvironVarName,
                String iFunctionName)
 {
     cStrTableStorageRootURL = EnvironmentHelpers.GetEnvironmentVariable(iTableStorageRootURLEnvironVarName);
     if (cStrTableStorageRootURL.EndsWith("/"))
     {
         cStrTableStorageRootURL.TrimEnd('/');
     }
     cStrConnectionString = EnvironmentHelpers.GetEnvironmentVariable(iConnectionStringEnvironVarName);
     cStrFunctionName     = iFunctionName;
     cCSAAccount          = CloudStorageAccount.Parse(cStrConnectionString);
     cCTeUsers            = new CloudTable(UsersTableURI, cCSAAccount.Credentials);
     cCTeProfiles         = new CloudTable(ProfilesTableURI, cCSAAccount.Credentials);
     cCTeFunctionHits     = new CloudTable(FunctionHitsTableURI, cCSAAccount.Credentials);
     cCTeFriendsLists     = new CloudTable(FriendsListsTableURI, cCSAAccount.Credentials);
 }
コード例 #28
0
 private static void SetupJenkinsEnvironment()
 {
     IsCI           = true;
     Provider       = "jenkins";
     Repository     = EnvironmentHelpers.GetEnvironmentVariable("GIT_URL");
     Commit         = EnvironmentHelpers.GetEnvironmentVariable("GIT_COMMIT");
     SourceRoot     = EnvironmentHelpers.GetEnvironmentVariable("WORKSPACE");
     PipelineId     = EnvironmentHelpers.GetEnvironmentVariable("BUILD_ID");
     PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("BUILD_NUMBER");
     PipelineUrl    = EnvironmentHelpers.GetEnvironmentVariable("BUILD_URL");
     JobUrl         = EnvironmentHelpers.GetEnvironmentVariable("JOB_URL");
     Branch         = EnvironmentHelpers.GetEnvironmentVariable("GIT_BRANCH");
     if (Branch?.IndexOf("origin/", StringComparison.Ordinal) == 0)
     {
         Branch = Branch.Substring(7);
     }
 }
コード例 #29
0
 private static void SetupGitlabEnvironment()
 {
     IsCI           = true;
     Provider       = "gitlab";
     Repository     = EnvironmentHelpers.GetEnvironmentVariable("CI_REPOSITORY_URL");
     Commit         = EnvironmentHelpers.GetEnvironmentVariable("CI_COMMIT_SHA");
     SourceRoot     = EnvironmentHelpers.GetEnvironmentVariable("CI_PROJECT_DIR");
     PipelineId     = EnvironmentHelpers.GetEnvironmentVariable("CI_PIPELINE_ID");
     PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("CI_PIPELINE_IID");
     PipelineUrl    = EnvironmentHelpers.GetEnvironmentVariable("CI_PIPELINE_URL");
     JobUrl         = EnvironmentHelpers.GetEnvironmentVariable("CI_JOB_URL");
     Branch         = EnvironmentHelpers.GetEnvironmentVariable("CI_COMMIT_BRANCH");
     if (string.IsNullOrWhiteSpace(Branch))
     {
         Branch = EnvironmentHelpers.GetEnvironmentVariable("CI_COMMIT_REF_NAME");
     }
 }
コード例 #30
0
 private static void SetupBitbucketEnvironment()
 {
     IsCI           = true;
     Provider       = "bitbucket";
     Repository     = EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_GIT_SSH_ORIGIN");
     Commit         = EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_COMMIT");
     Branch         = EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_BRANCH");
     Tag            = EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_TAG");
     SourceRoot     = EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_CLONE_DIR");
     WorkspacePath  = EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_CLONE_DIR");
     PipelineId     = EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_PIPELINE_UUID")?.Replace("}", string.Empty).Replace("{", string.Empty);
     PipelineNumber = EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_BUILD_NUMBER");
     PipelineName   = EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_REPO_FULL_NAME");
     PipelineUrl    = string.Format(
         "https://bitbucket.org/{0}/addon/pipelines/home#!/results/{1}",
         EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_REPO_FULL_NAME"),
         EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_BUILD_NUMBER"));
     JobUrl = PipelineUrl;
 }