-
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 buildkite extractor to a separate class
- Loading branch information
1 parent
d01f763
commit ee39589
Showing
4 changed files
with
155 additions
and
3 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 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,99 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../extractor" | ||
|
||
module Datadog | ||
module CI | ||
module Ext | ||
module Environment | ||
module Providers | ||
# Buildkite: https://buildkite.com/ | ||
# Environment variables docs: https://buildkite.com/docs/pipelines/environment-variables | ||
class Buildkite < Extractor | ||
private | ||
|
||
# overridden methods | ||
def provider_name | ||
"buildkite" | ||
end | ||
|
||
def job_url | ||
"#{env["BUILDKITE_BUILD_URL"]}##{env["BUILDKITE_JOB_ID"]}" | ||
end | ||
|
||
def pipeline_id | ||
env["BUILDKITE_BUILD_ID"] | ||
end | ||
|
||
def pipeline_name | ||
env["BUILDKITE_PIPELINE_SLUG"] | ||
end | ||
|
||
def pipeline_number | ||
env["BUILDKITE_BUILD_NUMBER"] | ||
end | ||
|
||
def pipeline_url | ||
env["BUILDKITE_BUILD_URL"] | ||
end | ||
|
||
def node_name | ||
env["BUILDKITE_AGENT_ID"] | ||
end | ||
|
||
def node_labels | ||
labels = env | ||
.select { |key| key.start_with?("BUILDKITE_AGENT_META_DATA_") } | ||
.map { |key, value| "#{key.to_s.sub("BUILDKITE_AGENT_META_DATA_", "").downcase}:#{value}" } | ||
.sort_by(&:length) | ||
|
||
labels.to_json unless labels.empty? | ||
end | ||
|
||
def workspace_path | ||
env["BUILDKITE_BUILD_CHECKOUT_PATH"] | ||
end | ||
|
||
def git_repository_url | ||
env["BUILDKITE_REPO"] | ||
end | ||
|
||
def git_commit_sha | ||
env["BUILDKITE_COMMIT"] | ||
end | ||
|
||
def git_branch | ||
env["BUILDKITE_BRANCH"] | ||
end | ||
|
||
def git_tag | ||
env["BUILDKITE_TAG"] | ||
end | ||
|
||
def git_commit_author_name | ||
env["BUILDKITE_BUILD_AUTHOR"] | ||
end | ||
|
||
def git_commit_author_email | ||
env["BUILDKITE_BUILD_AUTHOR_EMAIL"] | ||
end | ||
|
||
def git_commit_message | ||
env["BUILDKITE_MESSAGE"] | ||
end | ||
|
||
def ci_env_vars | ||
{ | ||
"BUILDKITE_BUILD_ID" => env["BUILDKITE_BUILD_ID"], | ||
"BUILDKITE_JOB_ID" => env["BUILDKITE_JOB_ID"] | ||
}.to_json | ||
end | ||
|
||
# buildkite-specific methods | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module Datadog | ||
module CI | ||
module Ext | ||
module Environment | ||
module Providers | ||
class Buildkite < Extractor | ||
private | ||
def provider_name: () -> "buildkite" | ||
|
||
def job_url: () -> ::String | ||
|
||
def pipeline_id: () -> String? | ||
|
||
def pipeline_name: () -> String? | ||
|
||
def pipeline_number: () -> String? | ||
|
||
def pipeline_url: () -> String? | ||
|
||
def node_name: () -> String? | ||
|
||
def node_labels: () -> String? | ||
|
||
def workspace_path: () -> 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? | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |