Added a buildkite detector for detecting the correct env vars in CI (#7933)
* Added a buildkite detector for detecting the correct env vars in CI * adding pending changelog entry * fixed PR logic to actually match the Buildkite Docs and simplified if statement, Fixed a few typos in comments and added PR to CHANGELOG_PENDING.md * made PR number fetch easier to read * fixing typo in comment
This commit is contained in:
parent
272c4643b2
commit
a5f72ddbeb
|
@ -1,4 +1,5 @@
|
||||||
### Improvements
|
### Improvements
|
||||||
|
* Adds CI detector for Buildkite [#7933](https://github.com/pulumi/pulumi/pull/7933)
|
||||||
|
|
||||||
- [CLI] Adding the ability to use `pulumi org set [name]` to set a default org
|
- [CLI] Adding the ability to use `pulumi org set [name]` to set a default org
|
||||||
to use when creating a stacks in the Pulumi Service backend or Self -hosted Service
|
to use when creating a stacks in the Pulumi Service backend or Self -hosted Service
|
||||||
|
|
56
sdk/go/common/util/ciutil/buildkite.go
Normal file
56
sdk/go/common/util/ciutil/buildkite.go
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
// Copyright 2016-2021, Pulumi Corporation.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package ciutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// buildkiteCI represents a Buildkite CI/CD system.
|
||||||
|
type buildkiteCI struct {
|
||||||
|
baseCI
|
||||||
|
}
|
||||||
|
|
||||||
|
// DetectVars detects the env vars for a Buildkite Build.
|
||||||
|
func (bci buildkiteCI) DetectVars() Vars {
|
||||||
|
v := Vars{Name: Buildkite}
|
||||||
|
// https://buildkite.com/docs/pipelines/environment-variables#bk-env-vars-buildkite-branch
|
||||||
|
v.BranchName = os.Getenv("BUILDKITE_BRANCH")
|
||||||
|
// https://buildkite.com/docs/pipelines/environment-variables#bk-env-vars-buildkite-build-id
|
||||||
|
v.BuildID = os.Getenv("BUILDKITE_BUILD_ID")
|
||||||
|
// https://buildkite.com/docs/pipelines/environment-variables#bk-env-vars-buildkite-build-number
|
||||||
|
v.BuildNumber = os.Getenv("BUILDKITE_BUILD_NUMBER")
|
||||||
|
// https://buildkite.com/docs/pipelines/environment-variables#bk-env-vars-buildkite-build-url
|
||||||
|
v.BuildURL = os.Getenv("BUILDKITE_BUILD_URL")
|
||||||
|
// https://buildkite.com/docs/pipelines/environment-variables#bk-env-vars-buildkite-message
|
||||||
|
// This is usually the commit message but can be other messages.
|
||||||
|
v.CommitMessage = os.Getenv("BUILDKITE_MESSAGE")
|
||||||
|
// https://buildkite.com/docs/pipelines/environment-variables#bk-env-vars-buildkite-pull-request
|
||||||
|
// If Buildkite's PR env var it is a pull request of the supplied number, else the build type is
|
||||||
|
// whatever Buildkite says it is. Pull requests are webhooks just like a standard push so this allows
|
||||||
|
// us to differentiate the two.
|
||||||
|
prNumber := os.Getenv("BUILDKITE_PULL_REQUEST")
|
||||||
|
if prNumber != "false" {
|
||||||
|
v.PRNumber = prNumber
|
||||||
|
v.BuildType = "PullRequest"
|
||||||
|
} else {
|
||||||
|
// https://buildkite.com/docs/pipelines/environment-variables#bk-env-vars-buildkite-source
|
||||||
|
v.BuildType = os.Getenv("BUILDKITE_SOURCE")
|
||||||
|
}
|
||||||
|
// https://buildkite.com/docs/pipelines/environment-variables#bk-env-vars-buildkite-commit
|
||||||
|
v.SHA = os.Getenv("BUILDKITE_COMMIT")
|
||||||
|
|
||||||
|
return v
|
||||||
|
}
|
|
@ -48,9 +48,11 @@ var detectors = map[SystemName]system{
|
||||||
EnvVarsToDetect: []string{"TF_BUILD"},
|
EnvVarsToDetect: []string{"TF_BUILD"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Buildkite: baseCI{
|
Buildkite: buildkiteCI{
|
||||||
Name: Buildkite,
|
baseCI: baseCI{
|
||||||
EnvVarsToDetect: []string{"BUILDKITE"},
|
Name: Buildkite,
|
||||||
|
EnvVarsToDetect: []string{"BUILDKITE"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
CircleCI: circleCICI{
|
CircleCI: circleCICI{
|
||||||
baseCI: baseCI{
|
baseCI: baseCI{
|
||||||
|
|
|
@ -35,6 +35,13 @@ func TestDetectVars(t *testing.T) {
|
||||||
"BUILD_BUILDID": buildNumber,
|
"BUILD_BUILDID": buildNumber,
|
||||||
"GITHUB_ACTIONS": "",
|
"GITHUB_ACTIONS": "",
|
||||||
},
|
},
|
||||||
|
Buildkite: {
|
||||||
|
"GITHUB_ACTIONS": "",
|
||||||
|
"TRAVIS": "",
|
||||||
|
"BUILDKITE": "true",
|
||||||
|
"BUILDKITE_BUILD_NUMBER": buildNumber,
|
||||||
|
"BUILDKITE_BUILD_ID": buildID,
|
||||||
|
},
|
||||||
CircleCI: {
|
CircleCI: {
|
||||||
"TRAVIS": "",
|
"TRAVIS": "",
|
||||||
"CIRCLECI": "true",
|
"CIRCLECI": "true",
|
||||||
|
|
Loading…
Reference in a new issue