Skip to content

Commit

Permalink
Update CI Visibility spec
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Aug 15, 2023
1 parent da0fe27 commit beb04a5
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 138 deletions.
45 changes: 40 additions & 5 deletions lib/datadog/ci/ext/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module Environment
TAG_PROVIDER_NAME = "ci.provider.name"
TAG_STAGE_NAME = "ci.stage.name"
TAG_WORKSPACE_PATH = "ci.workspace_path"
TAG_NODE_LABELS = 'ci.node.labels'
TAG_NODE_NAME = 'ci.node.name'
TAG_CI_ENV_VARS = "_dd.ci.env_vars"

PROVIDERS = [
Expand All @@ -33,7 +35,8 @@ module Environment
["JENKINS_URL", :extract_jenkins],
["TEAMCITY_VERSION", :extract_teamcity],
["TRAVIS", :extract_travis],
["BITRISE_BUILD_SLUG", :extract_bitrise]
["BITRISE_BUILD_SLUG", :extract_bitrise],
["CF_BUILD_ID", :extract_codefresh]
].freeze

module_function
Expand Down Expand Up @@ -168,7 +171,7 @@ def extract_bitbucket(env)
Core::Git::Ext::TAG_REPOSITORY_URL => env["BITBUCKET_GIT_SSH_ORIGIN"],
Core::Git::Ext::TAG_TAG => env["BITBUCKET_TAG"],
TAG_JOB_URL => url,
TAG_PIPELINE_ID => env["BITBUCKET_PIPELINE_UUID"] ? env["BITBUCKET_PIPELINE_UUID"].tr("{}", "") : nil,
TAG_PIPELINE_ID => env["BITBUCKET_PIPELINE_UUID"] && env["BITBUCKET_PIPELINE_UUID"].tr("{}", ""),
TAG_PIPELINE_NAME => env["BITBUCKET_REPO_FULL_NAME"],
TAG_PIPELINE_NUMBER => env["BITBUCKET_BUILD_NUMBER"],
TAG_PIPELINE_URL => url,
Expand Down Expand Up @@ -196,7 +199,7 @@ def extract_buddy(env)
end

def extract_buildkite(env)
{
tags = {
Core::Git::Ext::TAG_BRANCH => env["BUILDKITE_BRANCH"],
Core::Git::Ext::TAG_COMMIT_SHA => env["BUILDKITE_COMMIT"],
Core::Git::Ext::TAG_REPOSITORY_URL => env["BUILDKITE_REPO"],
Expand All @@ -216,6 +219,15 @@ def extract_buildkite(env)
"BUILDKITE_JOB_ID" => env["BUILDKITE_JOB_ID"]
}.to_json
}

extra_tags = 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)

tags[TAG_NODE_LABELS] = extra_tags.to_json unless extra_tags.empty?

tags
end

def extract_circle_ci(env)
Expand Down Expand Up @@ -274,7 +286,6 @@ def extract_github_actions(env)
def extract_gitlab(env)
commit_author_name, commit_author_email = extract_name_email(env["CI_COMMIT_AUTHOR"])

url = env["CI_PIPELINE_URL"]
{
Core::Git::Ext::TAG_BRANCH => env["CI_COMMIT_REF_NAME"],
Core::Git::Ext::TAG_COMMIT_SHA => env["CI_COMMIT_SHA"],
Expand All @@ -289,9 +300,11 @@ def extract_gitlab(env)
TAG_PIPELINE_ID => env["CI_PIPELINE_ID"],
TAG_PIPELINE_NAME => env["CI_PROJECT_PATH"],
TAG_PIPELINE_NUMBER => env["CI_PIPELINE_IID"],
TAG_PIPELINE_URL => url && url.gsub(%r{/-/pipelines/}, "/pipelines/"),
TAG_PIPELINE_URL => env["CI_PIPELINE_URL"],
TAG_PROVIDER_NAME => "gitlab",
TAG_WORKSPACE_PATH => env["CI_PROJECT_DIR"],
TAG_NODE_LABELS => env["CI_RUNNER_TAGS"],
TAG_NODE_NAME => env["CI_RUNNER_ID"],
Core::Git::Ext::TAG_COMMIT_MESSAGE => env["CI_COMMIT_MESSAGE"],
TAG_CI_ENV_VARS => {
"CI_PROJECT_URL" => env["CI_PROJECT_URL"],
Expand All @@ -308,6 +321,9 @@ def extract_jenkins(env)
name = name.gsub("/#{normalize_ref(branch)}", "") if branch
name = name.split("/").reject { |v| v.nil? || v.include?("=") }.join("/")
end

node_labels = env["NODE_LABELS"] && env["NODE_LABELS"].split.to_json

{
Core::Git::Ext::TAG_BRANCH => branch,
Core::Git::Ext::TAG_COMMIT_SHA => env["GIT_COMMIT"],
Expand All @@ -319,6 +335,8 @@ def extract_jenkins(env)
TAG_PIPELINE_URL => env["BUILD_URL"],
TAG_PROVIDER_NAME => "jenkins",
TAG_WORKSPACE_PATH => env["WORKSPACE"],
TAG_NODE_LABELS => node_labels,
TAG_NODE_NAME => env["NODE_NAME"],
TAG_CI_ENV_VARS => {
"DD_CUSTOM_TRACE_ID" => env["DD_CUSTOM_TRACE_ID"]
}.to_json
Expand Down Expand Up @@ -380,6 +398,23 @@ def extract_bitrise(env)
}
end

def extract_codefresh(env)
branch, tag = branch_or_tag(env["CF_BRANCH"])

{
TAG_PROVIDER_NAME => "codefresh",
TAG_PIPELINE_ID => env["CF_BUILD_ID"],
TAG_PIPELINE_NAME => env["CF_PIPELINE_NAME"],
TAG_PIPELINE_URL => env["CF_BUILD_URL"],
TAG_JOB_NAME => env["CF_STEP_NAME"],
Core::Git::Ext::TAG_BRANCH => branch,
Core::Git::Ext::TAG_TAG => tag,
TAG_CI_ENV_VARS => {
"CF_BUILD_ID" => env["CF_BUILD_ID"],
}.to_json
}
end

def extract_user_defined_git(env)
{
Core::Git::Ext::TAG_REPOSITORY_URL => env[Core::Git::Ext::ENV_REPOSITORY_URL],
Expand Down
30 changes: 30 additions & 0 deletions spec/datadog/ci/ext/fixtures/ci/buddy.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@
"git.tag": "v1.0"
}
],
[
{
"BUDDY": "true",
"BUDDY_EXECUTION_BRANCH": "my-name-is-rotag/fix-original-bug",
"BUDDY_EXECUTION_ID": "buddy-execution-id",
"BUDDY_EXECUTION_REVISION": "e5e13f8b7f8d5c6096a0501dc09b48eef05fea96",
"BUDDY_EXECUTION_REVISION_COMMITTER_EMAIL": "mikebenson@buddy.works",
"BUDDY_EXECUTION_REVISION_COMMITTER_NAME": "Mike Benson",
"BUDDY_EXECUTION_REVISION_MESSAGE": "Create buddy.yml",
"BUDDY_EXECUTION_TAG": "v1.0",
"BUDDY_EXECUTION_URL": "https://app.buddy.works/myworkspace/my-project/pipelines/pipeline/456/execution/5d9dc42c422f5a268b389d08",
"BUDDY_PIPELINE_ID": "456",
"BUDDY_PIPELINE_NAME": "Deploy to Production",
"BUDDY_SCM_URL": "https://github.com/buddyworks/my-project"
},
{
"ci.pipeline.id": "456/buddy-execution-id",
"ci.pipeline.name": "Deploy to Production",
"ci.pipeline.number": "buddy-execution-id",
"ci.pipeline.url": "https://app.buddy.works/myworkspace/my-project/pipelines/pipeline/456/execution/5d9dc42c422f5a268b389d08",
"ci.provider.name": "buddy",
"git.branch": "my-name-is-rotag/fix-original-bug",
"git.commit.committer.email": "mikebenson@buddy.works",
"git.commit.committer.name": "Mike Benson",
"git.commit.message": "Create buddy.yml",
"git.commit.sha": "e5e13f8b7f8d5c6096a0501dc09b48eef05fea96",
"git.repository_url": "https://github.com/buddyworks/my-project",
"git.tag": "v1.0"
}
],
[
{
"BUDDY": "true",
Expand Down
34 changes: 34 additions & 0 deletions spec/datadog/ci/ext/fixtures/ci/buildkite.json
Original file line number Diff line number Diff line change
Expand Up @@ -703,5 +703,39 @@
"git.commit.sha": "buildkite-git-commit",
"git.repository_url": "https://github.com/DataDog/dogweb.git"
}
],
[
{
"BUILDKITE": "true",
"BUILDKITE_AGENT_ID": "1a222222-e999-3636-8ddd-802222222222",
"BUILDKITE_AGENT_META_DATA_MYOTHERTAG": "my-other-value",
"BUILDKITE_AGENT_META_DATA_MYTAG": "my-value",
"BUILDKITE_BRANCH": "",
"BUILDKITE_BUILD_AUTHOR": "buildkite-git-commit-author-name",
"BUILDKITE_BUILD_AUTHOR_EMAIL": "buildkite-git-commit-author-email@datadoghq.com",
"BUILDKITE_BUILD_ID": "buildkite-pipeline-id",
"BUILDKITE_BUILD_NUMBER": "buildkite-pipeline-number",
"BUILDKITE_BUILD_URL": "buildkite-build-url",
"BUILDKITE_COMMIT": "buildkite-git-commit",
"BUILDKITE_JOB_ID": "buildkite-job-id",
"BUILDKITE_MESSAGE": "buildkite-git-commit-message",
"BUILDKITE_PIPELINE_SLUG": "buildkite-pipeline-name",
"BUILDKITE_TAG": ""
},
{
"_dd.ci.env_vars": "{\"BUILDKITE_BUILD_ID\":\"buildkite-pipeline-id\",\"BUILDKITE_JOB_ID\":\"buildkite-job-id\"}",
"ci.job.url": "buildkite-build-url#buildkite-job-id",
"ci.node.labels": "[\"mytag:my-value\",\"myothertag:my-other-value\"]",
"ci.node.name": "1a222222-e999-3636-8ddd-802222222222",
"ci.pipeline.id": "buildkite-pipeline-id",
"ci.pipeline.name": "buildkite-pipeline-name",
"ci.pipeline.number": "buildkite-pipeline-number",
"ci.pipeline.url": "buildkite-build-url",
"ci.provider.name": "buildkite",
"git.commit.author.email": "buildkite-git-commit-author-email@datadoghq.com",
"git.commit.author.name": "buildkite-git-commit-author-name",
"git.commit.message": "buildkite-git-commit-message",
"git.commit.sha": "buildkite-git-commit"
}
]
]
162 changes: 162 additions & 0 deletions spec/datadog/ci/ext/fixtures/ci/codefresh.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
[
[
{
"CF_BUILD_ID": "6410367cee516146a4c4c66e",
"CF_BUILD_URL": "https://g.codefresh.io/build/6410367cee516146a4c4c66e",
"CF_PIPELINE_NAME": "My simple project/Example Java Project Pipeline",
"CF_STEP_NAME": "mah-job-name"
},
{
"_dd.ci.env_vars": "{\"CF_BUILD_ID\":\"6410367cee516146a4c4c66e\"}",
"ci.job.name": "mah-job-name",
"ci.pipeline.id": "6410367cee516146a4c4c66e",
"ci.pipeline.name": "My simple project/Example Java Project Pipeline",
"ci.pipeline.url": "https://g.codefresh.io/build/6410367cee516146a4c4c66e",
"ci.provider.name": "codefresh"
}
],
[
{
"CF_BRANCH": "origin/master",
"CF_BUILD_ID": "6410367cee516146a4c4c66e",
"CF_BUILD_URL": "https://g.codefresh.io/build/6410367cee516146a4c4c66e",
"CF_PIPELINE_NAME": "My simple project/Example Java Project Pipeline",
"CF_STEP_NAME": "mah-job-name"
},
{
"_dd.ci.env_vars": "{\"CF_BUILD_ID\":\"6410367cee516146a4c4c66e\"}",
"ci.job.name": "mah-job-name",
"ci.pipeline.id": "6410367cee516146a4c4c66e",
"ci.pipeline.name": "My simple project/Example Java Project Pipeline",
"ci.pipeline.url": "https://g.codefresh.io/build/6410367cee516146a4c4c66e",
"ci.provider.name": "codefresh",
"git.branch": "master"
}
],
[
{
"CF_BRANCH": "refs/heads/feature/one",
"CF_BUILD_ID": "6410367cee516146a4c4c66e",
"CF_BUILD_URL": "https://g.codefresh.io/build/6410367cee516146a4c4c66e",
"CF_PIPELINE_NAME": "My simple project/Example Java Project Pipeline",
"CF_STEP_NAME": "mah-job-name"
},
{
"_dd.ci.env_vars": "{\"CF_BUILD_ID\":\"6410367cee516146a4c4c66e\"}",
"ci.job.name": "mah-job-name",
"ci.pipeline.id": "6410367cee516146a4c4c66e",
"ci.pipeline.name": "My simple project/Example Java Project Pipeline",
"ci.pipeline.url": "https://g.codefresh.io/build/6410367cee516146a4c4c66e",
"ci.provider.name": "codefresh",
"git.branch": "feature/one"
}
],
[
{
"CF_BRANCH": "origin/tags/0.1.0",
"CF_BUILD_ID": "6410367cee516146a4c4c66e",
"CF_BUILD_URL": "https://g.codefresh.io/build/6410367cee516146a4c4c66e",
"CF_PIPELINE_NAME": "My simple project/Example Java Project Pipeline",
"CF_STEP_NAME": "mah-job-name"
},
{
"_dd.ci.env_vars": "{\"CF_BUILD_ID\":\"6410367cee516146a4c4c66e\"}",
"ci.job.name": "mah-job-name",
"ci.pipeline.id": "6410367cee516146a4c4c66e",
"ci.pipeline.name": "My simple project/Example Java Project Pipeline",
"ci.pipeline.url": "https://g.codefresh.io/build/6410367cee516146a4c4c66e",
"ci.provider.name": "codefresh",
"git.tag": "0.1.0"
}
],
[
{
"CF_BRANCH": "refs/heads/tags/0.1.0",
"CF_BUILD_ID": "6410367cee516146a4c4c66e",
"CF_BUILD_URL": "https://g.codefresh.io/build/6410367cee516146a4c4c66e",
"CF_PIPELINE_NAME": "My simple project/Example Java Project Pipeline",
"CF_STEP_NAME": "mah-job-name"
},
{
"_dd.ci.env_vars": "{\"CF_BUILD_ID\":\"6410367cee516146a4c4c66e\"}",
"ci.job.name": "mah-job-name",
"ci.pipeline.id": "6410367cee516146a4c4c66e",
"ci.pipeline.name": "My simple project/Example Java Project Pipeline",
"ci.pipeline.url": "https://g.codefresh.io/build/6410367cee516146a4c4c66e",
"ci.provider.name": "codefresh",
"git.tag": "0.1.0"
}
],
[
{
"CF_BUILD_ID": "6410367cee516146a4c4c66e",
"CF_BUILD_URL": "https://g.codefresh.io/build/6410367cee516146a4c4c66e",
"CF_PIPELINE_NAME": "My simple project/Example Java Project Pipeline",
"CF_STEP_NAME": "mah-job-name",
"DD_GIT_BRANCH": "user-supplied-branch",
"DD_GIT_COMMIT_AUTHOR_DATE": "usersupplied-authordate",
"DD_GIT_COMMIT_AUTHOR_EMAIL": "usersupplied-authoremail",
"DD_GIT_COMMIT_AUTHOR_NAME": "usersupplied-authorname",
"DD_GIT_COMMIT_COMMITTER_DATE": "usersupplied-comitterdate",
"DD_GIT_COMMIT_COMMITTER_EMAIL": "usersupplied-comitteremail",
"DD_GIT_COMMIT_COMMITTER_NAME": "usersupplied-comittername",
"DD_GIT_COMMIT_MESSAGE": "usersupplied-message",
"DD_GIT_COMMIT_SHA": "b9f0fb3fdbb94c9d24b2c75b49663122a529e123",
"DD_GIT_REPOSITORY_URL": "git@github.com:DataDog/userrepo.git"
},
{
"_dd.ci.env_vars": "{\"CF_BUILD_ID\":\"6410367cee516146a4c4c66e\"}",
"ci.job.name": "mah-job-name",
"ci.pipeline.id": "6410367cee516146a4c4c66e",
"ci.pipeline.name": "My simple project/Example Java Project Pipeline",
"ci.pipeline.url": "https://g.codefresh.io/build/6410367cee516146a4c4c66e",
"ci.provider.name": "codefresh",
"git.branch": "user-supplied-branch",
"git.commit.author.date": "usersupplied-authordate",
"git.commit.author.email": "usersupplied-authoremail",
"git.commit.author.name": "usersupplied-authorname",
"git.commit.committer.date": "usersupplied-comitterdate",
"git.commit.committer.email": "usersupplied-comitteremail",
"git.commit.committer.name": "usersupplied-comittername",
"git.commit.message": "usersupplied-message",
"git.commit.sha": "b9f0fb3fdbb94c9d24b2c75b49663122a529e123",
"git.repository_url": "git@github.com:DataDog/userrepo.git"
}
],
[
{
"CF_BUILD_ID": "6410367cee516146a4c4c66e",
"CF_BUILD_URL": "https://g.codefresh.io/build/6410367cee516146a4c4c66e",
"CF_PIPELINE_NAME": "My simple project/Example Java Project Pipeline",
"CF_STEP_NAME": "mah-job-name",
"DD_GIT_COMMIT_AUTHOR_DATE": "usersupplied-authordate",
"DD_GIT_COMMIT_AUTHOR_EMAIL": "usersupplied-authoremail",
"DD_GIT_COMMIT_AUTHOR_NAME": "usersupplied-authorname",
"DD_GIT_COMMIT_COMMITTER_DATE": "usersupplied-comitterdate",
"DD_GIT_COMMIT_COMMITTER_EMAIL": "usersupplied-comitteremail",
"DD_GIT_COMMIT_COMMITTER_NAME": "usersupplied-comittername",
"DD_GIT_COMMIT_MESSAGE": "usersupplied-message",
"DD_GIT_COMMIT_SHA": "b9f0fb3fdbb94c9d24b2c75b49663122a529e123",
"DD_GIT_REPOSITORY_URL": "git@github.com:DataDog/userrepo.git",
"DD_GIT_TAG": "0.0.2"
},
{
"_dd.ci.env_vars": "{\"CF_BUILD_ID\":\"6410367cee516146a4c4c66e\"}",
"ci.job.name": "mah-job-name",
"ci.pipeline.id": "6410367cee516146a4c4c66e",
"ci.pipeline.name": "My simple project/Example Java Project Pipeline",
"ci.pipeline.url": "https://g.codefresh.io/build/6410367cee516146a4c4c66e",
"ci.provider.name": "codefresh",
"git.commit.author.date": "usersupplied-authordate",
"git.commit.author.email": "usersupplied-authoremail",
"git.commit.author.name": "usersupplied-authorname",
"git.commit.committer.date": "usersupplied-comitterdate",
"git.commit.committer.email": "usersupplied-comitteremail",
"git.commit.committer.name": "usersupplied-comittername",
"git.commit.message": "usersupplied-message",
"git.commit.sha": "b9f0fb3fdbb94c9d24b2c75b49663122a529e123",
"git.repository_url": "git@github.com:DataDog/userrepo.git",
"git.tag": "0.0.2"
}
]
]
Loading

0 comments on commit beb04a5

Please sign in to comment.