Skip to content

Commit

Permalink
Merge pull request #50 from lypht/master
Browse files Browse the repository at this point in the history
adds google cloud build provider, fixes #49
  • Loading branch information
maplebed authored Oct 14, 2019
2 parents 0f99f3c + c3a697d commit 75759c9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ There are several other optional enviornment variables that will adjust the beha

* `BUILDEVENT_DATASET` sets the Honeycomb dataset to use. The default is `buildevents`
* `BUILDEVENT_APIHOST` sets the API target for sending Honeycomb traces. Default is `https://api.honeycomb.io/`
* `BUILDEVENT_CIPROVIDER` if set, a field in all spans named `ci_provider` will contain this value. If unset, `buildevents` will inspect the environment to try and detect Travis-CI, CircleCI, GitLab-CI, and Jenkins-X (by looking for the environment variables `TRAVIS`, `CIRCLECI`, `GITLAB_CI`, and `JENKINS-X` respectively). If either Travis-CI, CircleCI, GitLab-CI, or Jenkins-X are detected, `buildevents` will add a number of additional fields from the environment, such as the branch name, the repository, the build number, and so on. If detection fails and you are on Travis-CI, CircleCI, GitLab-CI, or Jenkins-X setting this to `Travis-CI`, `CircleCI`, `GitLab-CI`, or `Jenkins-X` precisely will also trigger the automatic field additions.
* `BUILDEVENT_CIPROVIDER` if set, a field in all spans named `ci_provider` will contain this value. If unset, `buildevents` will inspect the environment to try and detect Travis-CI, CircleCI, GitLab-CI, Jenkins-X, and Google-Cloud-Build (by looking for the environment variables `TRAVIS`, `CIRCLECI`, `GITLAB_CI`, `JENKINS-X`, and `GOOGLE-CLOUD-BUILD` respectively). If either Travis-CI, CircleCI, GitLab-CI, Jenkins-X, or Google-Cloud-Build are detected, `buildevents` will add a number of additional fields from the environment, such as the branch name, the repository, the build number, and so on. If detection fails and you are on Travis-CI, CircleCI, GitLab-CI, Jenkins-X, or Google-Cloud-Build setting this to `Travis-CI`, `CircleCI`, `GitLab-CI`, `Jenkins-X`, or `Google-Cloud-Build` precisely will also trigger the automatic field additions.
* `BUILDEVENT_FILE` if set, is used as the path of a text file holding arbitrary key=val pairs (multi-line-capable, logfmt style) that will be added to the Honeycomb event.

## Trace Identifier
Expand All @@ -64,6 +64,7 @@ The Build ID may already be available in the environment for your build:
* CircleCI: `CIRCLE_BUILD_NUM` (the build number for this job if you're not using workflows)
* GitLab-CI: `CI_PIPELINE_ID`
* JenkinsX: `JENKINSX_BUILD_NUMBER`
* Google-Cloud-Build: `BUILD_ID`
# Use

Now that `buildevents` is installed and configured, actually generating spans to send to Honeycomb involves invoking `buildevents` in various places throughout your build config.
Expand Down
2 changes: 2 additions & 0 deletions cmd_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ about your Continuous Integration builds.`,
prov = providerGitLab
} else if _, present := os.LookupEnv("JENKINS-X"); present {
prov = providerJenkinsX
} else if _, present := os.LookupEnv("GOOGLE-CLOUD-BUILD"); present {
prov = providerGoogleCloudBuild
}
}
if prov != "" {
Expand Down
9 changes: 9 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ func providerInfo(provider string, ev *libhoney.Event) {
"PULL_NUMBER": "pr_number",
"REPO_NAME": "repo",
}

case "google-cloud-build", "cloud-build", "gcb":
envVars = map[string]string{
"BRANCH_NAME": "branch",
"BUILD_ID": "build_num",
"HEAD_BRANCH": "pr_branch",
"REPO_OWNER": "pr_user",
"REPO_NAME": "repo",
}
}
for envVar, fieldName := range envVars {
if val, ok := os.LookupEnv(envVar); ok {
Expand Down
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
var Version = "dev"

const (
providerTravis = "Travis-CI"
providerCircle = "CircleCI"
providerGitLab = "GitLab-CI"
providerJenkinsX = "Jenkins-X"
providerTravis = "Travis-CI"
providerCircle = "CircleCI"
providerGitLab = "GitLab-CI"
providerJenkinsX = "Jenkins-X"
providerGoogleCloudBuild = "Google-Cloud-Build"
)

func main() {
Expand Down

0 comments on commit 75759c9

Please sign in to comment.