-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract Azure environment extractor to its own class
- Loading branch information
1 parent
b5c77ba
commit 895ee04
Showing
8 changed files
with
223 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "extractor" | ||
|
||
module Datadog | ||
module CI | ||
module Ext | ||
module Providers | ||
# Azure Pipelines: https://azure.microsoft.com/en-us/products/devops/pipelines | ||
# Environment variables docs: https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml | ||
class Azure < Extractor | ||
private | ||
|
||
# overridden methods | ||
def provider_name | ||
"azurepipelines" | ||
end | ||
|
||
def pipeline_url | ||
return unless url_defined? | ||
|
||
@pipeline_url ||= "#{team_foundation_server_uri}#{team_project_id}/_build/results?buildId=#{build_id}" | ||
end | ||
|
||
def job_url | ||
return unless url_defined? | ||
|
||
@job_url ||= "#{pipeline_url}&view=logs&j=#{env["SYSTEM_JOBID"]}&t=#{env["SYSTEM_TASKINSTANCEID"]}" | ||
end | ||
|
||
def workspace_path | ||
env["BUILD_SOURCESDIRECTORY"] | ||
end | ||
|
||
def pipeline_id | ||
build_id | ||
end | ||
|
||
def pipeline_number | ||
build_id | ||
end | ||
|
||
def pipeline_name | ||
env["BUILD_DEFINITIONNAME"] | ||
end | ||
|
||
def stage_name | ||
env["SYSTEM_STAGEDISPLAYNAME"] | ||
end | ||
|
||
def job_name | ||
env["SYSTEM_JOBDISPLAYNAME"] | ||
end | ||
|
||
def git_repository_url | ||
env["SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI"] || env["BUILD_REPOSITORY_URI"] | ||
end | ||
|
||
def git_commit_sha | ||
env["SYSTEM_PULLREQUEST_SOURCECOMMITID"] || env["BUILD_SOURCEVERSION"] | ||
end | ||
|
||
def git_branch | ||
return @branch if defined?(@branch) | ||
|
||
set_branch_and_tag | ||
@branch | ||
end | ||
|
||
def git_tag | ||
return @tag if defined?(@tag) | ||
|
||
set_branch_and_tag | ||
@tag | ||
end | ||
|
||
def git_commit_author_name | ||
env["BUILD_REQUESTEDFORID"] | ||
end | ||
|
||
def git_commit_author_email | ||
env["BUILD_REQUESTEDFOREMAIL"] | ||
end | ||
|
||
def git_commit_message | ||
env["BUILD_SOURCEVERSIONMESSAGE"] | ||
end | ||
|
||
def ci_env_vars | ||
{ | ||
"SYSTEM_TEAMPROJECTID" => env["SYSTEM_TEAMPROJECTID"], | ||
"BUILD_BUILDID" => env["BUILD_BUILDID"], | ||
"SYSTEM_JOBID" => env["SYSTEM_JOBID"] | ||
}.to_json | ||
end | ||
|
||
# azure-specific logic | ||
|
||
def build_id | ||
env["BUILD_BUILDID"] | ||
end | ||
|
||
def team_foundation_server_uri | ||
env["SYSTEM_TEAMFOUNDATIONSERVERURI"] | ||
end | ||
|
||
def team_project_id | ||
env["SYSTEM_TEAMPROJECTID"] | ||
end | ||
|
||
def url_defined? | ||
!(build_id && team_foundation_server_uri && team_project_id).nil? | ||
end | ||
|
||
def set_branch_and_tag | ||
@branch, @tag = branch_or_tag( | ||
env["SYSTEM_PULLREQUEST_SOURCEBRANCH"] || env["BUILD_SOURCEBRANCH"] || env["BUILD_SOURCEBRANCHNAME"] | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ module Datadog | |
private | ||
|
||
@github_repo_provider: bool | ||
@url: String | ||
|
||
def provider_name: () -> "appveyor" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module Datadog | ||
module CI | ||
module Ext | ||
module Providers | ||
class Azure < Extractor | ||
private | ||
|
||
@pipeline_url: String | ||
@job_url: String | ||
|
||
def provider_name: () -> "azurepipelines" | ||
|
||
def pipeline_url: () -> String? | ||
|
||
def job_url: () -> String? | ||
|
||
def workspace_path: () -> String? | ||
|
||
def pipeline_id: () -> String? | ||
|
||
def pipeline_number: () -> String? | ||
|
||
def pipeline_name: () -> String? | ||
|
||
def stage_name: () -> String? | ||
|
||
def job_name: () -> String? | ||
|
||
def git_repository_url: () -> String? | ||
|
||
def git_commit_sha: () -> String? | ||
|
||
def git_branch: () -> String? | ||
|
||
def git_tag: () -> String? | ||
|
||
def git_commit_author_name: () -> String? | ||
|
||
def git_commit_author_email: () -> String? | ||
|
||
def git_commit_message: () -> String? | ||
|
||
def ci_env_vars: () -> String? | ||
|
||
def build_id: () -> String? | ||
|
||
def team_foundation_server_uri: () -> String? | ||
|
||
def team_project_id: () -> String? | ||
|
||
def url_defined?: () -> bool | ||
|
||
def set_branch_and_tag: () -> [String?, String?] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters