Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Build Skipping configuration #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 44 additions & 16 deletions buildkite/resource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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 @@ -235,22 +251,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 repositoryProvider `json:"provider,omitempty"`
ProviderSettings map[string]interface{} `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 repositoryProvider `json:"provider,omitempty"`
ProviderSettings map[string]interface{} `json:"provider_settings,omitempty"`
Steps []Step `json:"steps"`
}

type repositoryProvider struct {
Expand Down Expand Up @@ -379,6 +399,10 @@ func updatePipelineFromAPI(d *schema.ResourceData, p *Pipeline) error {
d.Set("builds_url", p.BuildsURL)
d.Set("branch_configuration", p.BranchConfiguration)
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 @@ -443,6 +467,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