-
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.
- Loading branch information
1 parent
91943fb
commit 7a39ffe
Showing
5 changed files
with
148 additions
and
31 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,90 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../extractor" | ||
|
||
module Datadog | ||
module CI | ||
module Ext | ||
module Environment | ||
module Providers | ||
# Jenkins: https://www.jenkins.io/ | ||
# Environment variables docs: https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables | ||
class Jenkins < Extractor | ||
private | ||
|
||
# overridden methods | ||
def provider_name | ||
"jenkins" | ||
end | ||
|
||
def pipeline_id | ||
env["BUILD_TAG"] | ||
end | ||
|
||
def pipeline_name | ||
if (name = env["JOB_NAME"]) | ||
name = name.gsub("/#{normalize_ref(git_branch)}", "") if git_branch | ||
name = name.split("/").reject { |v| v.nil? || v.include?("=") }.join("/") | ||
end | ||
name | ||
end | ||
|
||
def pipeline_number | ||
env["BUILD_NUMBER"] | ||
end | ||
|
||
def pipeline_url | ||
env["BUILD_URL"] | ||
end | ||
|
||
def workspace_path | ||
env["WORKSPACE"] | ||
end | ||
|
||
def node_name | ||
env["NODE_NAME"] | ||
end | ||
|
||
def node_labels | ||
env["NODE_LABELS"] && env["NODE_LABELS"].split.to_json | ||
end | ||
|
||
def git_repository_url | ||
env["GIT_URL"] || env["GIT_URL_1"] | ||
end | ||
|
||
def git_commit_sha | ||
env["GIT_COMMIT"] | ||
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 ci_env_vars | ||
{ | ||
"DD_CUSTOM_TRACE_ID" => env["DD_CUSTOM_TRACE_ID"] | ||
}.to_json | ||
end | ||
|
||
# jenkins-specific methods | ||
|
||
def set_branch_and_tag | ||
@branch, @tag = branch_or_tag(env["GIT_BRANCH"]) | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module Datadog | ||
module CI | ||
module Ext | ||
module Environment | ||
module Providers | ||
class Jenkins < Extractor | ||
private | ||
def provider_name: () -> "jenkins" | ||
|
||
def pipeline_id: () -> String? | ||
|
||
def pipeline_name: () -> String? | ||
|
||
def pipeline_number: () -> String? | ||
|
||
def pipeline_url: () -> String? | ||
|
||
def workspace_path: () -> String? | ||
|
||
def node_name: () -> String? | ||
|
||
def node_labels: () -> String? | ||
|
||
def git_repository_url: () -> String? | ||
|
||
def git_commit_sha: () -> String? | ||
|
||
def git_branch: () -> String? | ||
|
||
def git_tag: () -> String? | ||
|
||
def ci_env_vars: () -> String? | ||
|
||
def set_branch_and_tag: () -> [String?, String?] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |