Class: Datadog::CI::Ext::Environment::Providers::Buildkite

Inherits:
Base
  • Object
show all
Defined in:
lib/datadog/ci/ext/environment/providers/buildkite.rb

Overview

Buildkite: buildkite.com/ Environment variables docs: buildkite.com/docs/pipelines/environment-variables

Instance Attribute Summary

Attributes inherited from Base

#env

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#additional_tags, #git_branch_or_tag, #git_commit_author_date, #git_commit_committer_date, #git_commit_committer_email, #git_commit_committer_name, #initialize, #job_name, #stage_name

Constructor Details

This class inherits a constructor from Datadog::CI::Ext::Environment::Providers::Base

Class Method Details

.handles?(env) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 15

def self.handles?(env)
  env.key?("BUILDKITE")
end

Instance Method Details

#ci_env_varsObject



88
89
90
91
92
93
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 88

def ci_env_vars
  {
    "BUILDKITE_BUILD_ID" => env["BUILDKITE_BUILD_ID"],
    "BUILDKITE_JOB_ID" => env["BUILDKITE_JOB_ID"]
  }.to_json
end

#git_branchObject



68
69
70
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 68

def git_branch
  env["BUILDKITE_BRANCH"]
end

#git_commit_author_emailObject



80
81
82
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 80

def git_commit_author_email
  env["BUILDKITE_BUILD_AUTHOR_EMAIL"]
end

#git_commit_author_nameObject



76
77
78
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 76

def git_commit_author_name
  env["BUILDKITE_BUILD_AUTHOR"]
end

#git_commit_messageObject



84
85
86
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 84

def git_commit_message
  env["BUILDKITE_MESSAGE"]
end

#git_commit_shaObject



64
65
66
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 64

def git_commit_sha
  env["BUILDKITE_COMMIT"]
end

#git_repository_urlObject



60
61
62
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 60

def git_repository_url
  env["BUILDKITE_REPO"]
end

#git_tagObject



72
73
74
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 72

def git_tag
  env["BUILDKITE_TAG"]
end

#job_urlObject



23
24
25
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 23

def job_url
  "#{env["BUILDKITE_BUILD_URL"]}##{env["BUILDKITE_JOB_ID"]}"
end

#node_labelsObject



47
48
49
50
51
52
53
54
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 47

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

#node_nameObject



43
44
45
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 43

def node_name
  env["BUILDKITE_AGENT_ID"]
end

#pipeline_idObject



27
28
29
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 27

def pipeline_id
  env["BUILDKITE_BUILD_ID"]
end

#pipeline_nameObject



31
32
33
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 31

def pipeline_name
  env["BUILDKITE_PIPELINE_SLUG"]
end

#pipeline_numberObject



35
36
37
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 35

def pipeline_number
  env["BUILDKITE_BUILD_NUMBER"]
end

#pipeline_urlObject



39
40
41
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 39

def pipeline_url
  env["BUILDKITE_BUILD_URL"]
end

#provider_nameObject



19
20
21
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 19

def provider_name
  Provider::BUILDKITE
end

#workspace_pathObject



56
57
58
# File 'lib/datadog/ci/ext/environment/providers/buildkite.rb', line 56

def workspace_path
  env["BUILDKITE_BUILD_CHECKOUT_PATH"]
end