internal static void ReloadEnvironmentData() { // ********** // Setup variables // ********** Provider = null; PipelineId = null; PipelineName = null; PipelineNumber = null; PipelineUrl = null; JobUrl = null; JobName = null; StageName = null; WorkspacePath = null; Repository = null; Commit = null; Branch = null; Tag = null; AuthorName = null; AuthorEmail = null; AuthorDate = null; CommitterName = null; CommitterEmail = null; CommitterDate = null; Message = null; SourceRoot = null; GitInfo gitInfo = GitInfo.GetCurrent(); if (EnvironmentHelpers.GetEnvironmentVariable("TRAVIS") != null) { SetupTravisEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("CIRCLECI") != null) { SetupCircleCiEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("JENKINS_URL") != null) { SetupJenkinsEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("GITLAB_CI") != null) { SetupGitlabEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR") != null) { SetupAppveyorEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("TF_BUILD") != null) { SetupAzurePipelinesEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_COMMIT") != null) { SetupBitbucketEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("GITHUB_SHA") != null) { SetupGithubActionsEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("TEAMCITY_VERSION") != null) { SetupTeamcityEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE") != null) { SetupBuildkiteEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("BITRISE_BUILD_SLUG") != null) { SetupBitriseEnvironment(); } else { Branch = gitInfo.Branch; Commit = gitInfo.Commit; Repository = gitInfo.Repository; SourceRoot = gitInfo.SourceRoot; WorkspacePath = gitInfo.SourceRoot; } // ********** // Add Author, Committer and Message from git // ********** // Merge commits have a different commit hash from the one reported by the CI. if (gitInfo.Commit == Commit) { AuthorName = gitInfo.AuthorName; AuthorEmail = gitInfo.AuthorEmail; AuthorDate = gitInfo.AuthorDate; CommitterName = gitInfo.CommitterName; CommitterEmail = gitInfo.CommitterEmail; CommitterDate = gitInfo.CommitterDate; Message = gitInfo.Message; } // ********** // Remove sensitive info from repository url // ********** if (Uri.TryCreate(Repository, UriKind.Absolute, out Uri repository)) { if (!string.IsNullOrEmpty(repository.UserInfo)) { Repository = repository.GetComponents(UriComponents.Fragment | UriComponents.Query | UriComponents.Path | UriComponents.Port | UriComponents.Host | UriComponents.Scheme, UriFormat.SafeUnescaped); } } // ********** // Expand ~ in Paths // ********** SourceRoot = ExpandPath(SourceRoot); WorkspacePath = ExpandPath(WorkspacePath); // ********** // Clean Refs // ********** CleanBranchAndTag(); }
internal void ReloadEnvironmentData() { // ********** // Setup variables // ********** Provider = null; PipelineId = null; PipelineName = null; PipelineNumber = null; PipelineUrl = null; JobUrl = null; JobName = null; StageName = null; WorkspacePath = null; Repository = null; Commit = null; Branch = null; Tag = null; AuthorName = null; AuthorEmail = null; AuthorDate = null; CommitterName = null; CommitterEmail = null; CommitterDate = null; Message = null; SourceRoot = null; GitInfo gitInfo = GitInfo.GetCurrent(); if (EnvironmentHelpers.GetEnvironmentVariable("TRAVIS") != null) { SetupTravisEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("CIRCLECI") != null) { SetupCircleCiEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("JENKINS_URL") != null) { SetupJenkinsEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("GITLAB_CI") != null) { SetupGitlabEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("APPVEYOR") != null) { SetupAppveyorEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("TF_BUILD") != null) { SetupAzurePipelinesEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("BITBUCKET_COMMIT") != null) { SetupBitbucketEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("GITHUB_SHA") != null) { SetupGithubActionsEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("TEAMCITY_VERSION") != null) { SetupTeamcityEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("BUILDKITE") != null) { SetupBuildkiteEnvironment(); } else if (EnvironmentHelpers.GetEnvironmentVariable("BITRISE_BUILD_SLUG") != null) { SetupBitriseEnvironment(); } else { Branch = gitInfo.Branch; Commit = gitInfo.Commit; Repository = gitInfo.Repository; SourceRoot = gitInfo.SourceRoot; WorkspacePath = gitInfo.SourceRoot; } // ********** // Add Author, Committer and Message from git // ********** // Merge commits have a different commit hash from the one reported by the CI. if (gitInfo.Commit == Commit) { if (string.IsNullOrEmpty(AuthorName)) { AuthorName = gitInfo.AuthorName; } if (string.IsNullOrEmpty(AuthorEmail)) { AuthorEmail = gitInfo.AuthorEmail; } if (AuthorDate is null) { AuthorDate = gitInfo.AuthorDate; } if (string.IsNullOrEmpty(CommitterName)) { CommitterName = gitInfo.CommitterName; } if (string.IsNullOrEmpty(CommitterEmail)) { CommitterEmail = gitInfo.CommitterEmail; } if (CommitterDate is null) { CommitterDate = gitInfo.CommitterDate; } if (string.IsNullOrEmpty(Message)) { Message = gitInfo.Message; } } // ********** // Remove sensitive info from repository url // ********** if (Uri.TryCreate(Repository, UriKind.Absolute, out Uri repository)) { if (!string.IsNullOrEmpty(repository.UserInfo)) { Repository = repository.GetComponents(UriComponents.Fragment | UriComponents.Query | UriComponents.Path | UriComponents.Port | UriComponents.Host | UriComponents.Scheme, UriFormat.SafeUnescaped); } } // ********** // Expand ~ in Paths // ********** SourceRoot = ExpandPath(SourceRoot); WorkspacePath = ExpandPath(WorkspacePath); // ********** // Custom environment variables. // ********** Branch = GetEnvironmentVariableIfIsNotEmpty("SIGNALFX_GIT_BRANCH", Branch); Tag = GetEnvironmentVariableIfIsNotEmpty("SIGNALFX_GIT_TAG", Tag); Repository = GetEnvironmentVariableIfIsNotEmpty("SIGNALFX_GIT_REPOSITORY_URL", Repository); Commit = GetEnvironmentVariableIfIsNotEmpty("SIGNALFX_GIT_COMMIT_SHA", Commit); Message = GetEnvironmentVariableIfIsNotEmpty("SIGNALFX_GIT_COMMIT_MESSAGE", Message); AuthorName = GetEnvironmentVariableIfIsNotEmpty("SIGNALFX_GIT_COMMIT_AUTHOR_NAME", AuthorName); AuthorEmail = GetEnvironmentVariableIfIsNotEmpty("SIGNALFX_GIT_COMMIT_AUTHOR_EMAIL", AuthorEmail); AuthorDate = GetDateTimeOffsetEnvironmentVariableIfIsNotEmpty("SIGNALFX_GIT_COMMIT_AUTHOR_DATE", AuthorDate); CommitterName = GetEnvironmentVariableIfIsNotEmpty("SIGNALFX_GIT_COMMIT_COMMITTER_NAME", CommitterName); CommitterEmail = GetEnvironmentVariableIfIsNotEmpty("SIGNALFX_GIT_COMMIT_COMMITTER_EMAIL", CommitterEmail); CommitterDate = GetDateTimeOffsetEnvironmentVariableIfIsNotEmpty("SIGNALFX_GIT_COMMIT_COMMITTER_DATE", CommitterDate); // ********** // Clean Refs // ********** CleanBranchAndTag(); // ********** // Try load CodeOwners // ********** if (!string.IsNullOrEmpty(SourceRoot)) { foreach (var codeOwnersPath in GetCodeOwnersPaths(SourceRoot)) { Log.Debug("Looking for CODEOWNERS file in: {path}", codeOwnersPath); if (File.Exists(codeOwnersPath)) { Log.Debug("CODEOWNERS file found: {path}", codeOwnersPath); CodeOwners = new CodeOwners(codeOwnersPath); break; } } }