Skip to content

Commit

Permalink
Add support for Build Skipping configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
tucksaun committed Mar 5, 2019
1 parent dd99c2a commit 4bd700c
Showing 1 changed file with 44 additions and 16 deletions.
60 changes: 44 additions & 16 deletions buildkite/resource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ func resourcePipeline() *schema.Resource {
Optional: true,
Default: "master",
},
"skip_queued_branch_builds": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
},
"skip_queued_branch_builds_filter": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"cancel_running_branch_builds": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
},
"cancel_running_branch_builds_filter": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"env": &schema.Schema{
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -140,22 +156,26 @@ func resourcePipeline() *schema.Resource {
}

type Pipeline struct {
Id string `json:"id,omitempty"`
Environment map[string]string `json:"env,omitempty"`
Slug string `json:"slug,omitempty"`
WebURL string `json:"web_url,omitempty"`
BuildsURL string `json:"builds_url,omitempty"`
Url string `json:"url,omitempty"`
DefaultBranch string `json:"default_branch,omitempty"`
BadgeURL string `json:"badge_url,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
Repository string `json:"repository,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
BranchConfiguration string `json:"branch_configuration,omitempty"`
Provider BuildkiteProvider `json:"provider,omitempty"`
ProviderSettings map[string]string `json:"provider_settings,omitempty"`
Steps []Step `json:"steps"`
Id string `json:"id,omitempty"`
Environment map[string]string `json:"env,omitempty"`
Slug string `json:"slug,omitempty"`
WebURL string `json:"web_url,omitempty"`
BuildsURL string `json:"builds_url,omitempty"`
Url string `json:"url,omitempty"`
DefaultBranch string `json:"default_branch,omitempty"`
BadgeURL string `json:"badge_url,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
Repository string `json:"repository,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
BranchConfiguration string `json:"branch_configuration,omitempty"`
SkipQueuedBranchBuilds bool `json:"skip_queued_branch_builds,omitempty"`
SkipQueuedBranchBuildsFilter string `json:"skip_queued_branch_builds_filter,omitempty"`
CancelRunningBranchBuilds bool `json:"cancel_running_branch_builds,omitempty"`
CancelRunningBranchBuildsFilter string `json:"cancel_running_branch_builds_filter,omitempty"`
Provider BuildkiteProvider `json:"provider,omitempty"`
ProviderSettings map[string]string `json:"provider_settings,omitempty"`
Steps []Step `json:"steps"`
}

type BuildkiteProvider struct {
Expand Down Expand Up @@ -260,6 +280,10 @@ func updatePipelineFromAPI(d *schema.ResourceData, p *Pipeline) {
d.Set("provider_settings", p.Provider.Settings)
d.Set("webhook_url", p.Provider.WebhookURL)
d.Set("default_branch", p.DefaultBranch)
d.Set("skip_queued_branch_builds", p.SkipQueuedBranchBuilds)
d.Set("skip_queued_branch_builds_filter", p.SkipQueuedBranchBuildsFilter)
d.Set("cancel_running_branch_builds", p.CancelRunningBranchBuilds)
d.Set("cancel_running_branch_builds_filter", p.CancelRunningBranchBuildsFilter)

stepMap := make([]interface{}, len(p.Steps))
for i, element := range p.Steps {
Expand Down Expand Up @@ -288,6 +312,10 @@ func preparePipelineRequestPayload(d *schema.ResourceData) *Pipeline {
req.Slug = d.Get("slug").(string)
req.Repository = d.Get("repository").(string)
req.BranchConfiguration = d.Get("branch_configuration").(string)
req.SkipQueuedBranchBuilds = d.Get("skip_queued_branch_builds").(bool)
req.SkipQueuedBranchBuildsFilter = d.Get("skip_queued_branch_builds_filter").(string)
req.CancelRunningBranchBuilds = d.Get("cancel_running_branch_builds").(bool)
req.CancelRunningBranchBuildsFilter = d.Get("cancel_running_branch_builds_filter").(string)
req.Environment = map[string]string{}
for k, vI := range d.Get("env").(map[string]interface{}) {
req.Environment[k] = vI.(string)
Expand Down

0 comments on commit 4bd700c

Please sign in to comment.