Skip to content

Commit

Permalink
Use the job to target the step to update
Browse files Browse the repository at this point in the history
  • Loading branch information
keithpitt committed Oct 23, 2018
1 parent 7176b66 commit fd15306
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
2 changes: 0 additions & 2 deletions api/buildkite.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type Client struct {
Agents *AgentsService
Pings *PingsService
Jobs *JobsService
Steps *StepsService
Chunks *ChunksService
MetaData *MetaDataService
HeaderTimes *HeaderTimesService
Expand All @@ -67,7 +66,6 @@ func NewClient(httpClient *http.Client) *Client {
c.Agents = &AgentsService{c}
c.Pings = &PingsService{c}
c.Jobs = &JobsService{c}
c.Steps = &StepsService{c}
c.Chunks = &ChunksService{c}
c.MetaData = &MetaDataService{c}
c.HeaderTimes = &HeaderTimesService{c}
Expand Down
12 changes: 12 additions & 0 deletions api/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,15 @@ func (js *JobsService) Finish(job *Job) (*Response, error) {

return js.client.Do(req, nil)
}

// Updates a step
func (js *JobsService) StepUpdate(jobId string, stepUpdate *StepUpdate) (*Response, error) {
u := fmt.Sprintf("jobs/%s/step_update", jobId)

req, err := js.client.NewRequest("PUT", u, stepUpdate)
if err != nil {
return nil, err
}

return js.client.Do(req, nil)
}
22 changes: 0 additions & 22 deletions api/steps.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
package api

import (
"fmt"
)

// StepsService handles communication with the step related methods of the
// Buildkite Agent API.
type StepsService struct {
client *Client
}

// StepUpdate represents a change request to a step
type StepUpdate struct {
UUID string `json:"uuid,omitempty"`
Attribute string `json:"attribute,omitempty"`
Value string `json:"value,omitempty"`
Append bool `json:"append,omitempty"`
}

// Updates a step
func (js *StepsService) Update(stepId string, stepUpdate *StepUpdate) (*Response, error) {
u := fmt.Sprintf("steps/%s", stepId)

req, err := js.client.NewRequest("PUT", u, stepUpdate)
if err != nil {
return nil, err
}

return js.client.Do(req, nil)
}
12 changes: 6 additions & 6 deletions clicommand/step_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var StepUpdateHelpDescription = `Usage:
Description:
Update an attribute of a step
Update an attribute of a step associated with a job
Example:
Expand All @@ -32,7 +32,7 @@ type StepUpdateConfig struct {
Attribute string `cli:"arg:0" label:"attribute" validate:"required"`
Value string `cli:"arg:1" label:"value" validate:"required"`
Append bool `cli:"append"`
Step string `cli:"step" validate:"required"`
Job string `cli:"job" validate:"required"`
AgentAccessToken string `cli:"agent-access-token" validate:"required"`
Endpoint string `cli:"endpoint" validate:"required"`
NoColor bool `cli:"no-color"`
Expand All @@ -46,10 +46,10 @@ var StepUpdateCommand = cli.Command{
Description: StepUpdateHelpDescription,
Flags: []cli.Flag{
cli.StringFlag{
Name: "step",
Name: "job",
Value: "",
Usage: "Target the step of a specific step",
EnvVar: "BUILDKITE_STEP_ID",
Usage: "Target the step of a specific job in the build",
EnvVar: "BUILDKITE_JOB_ID",
},
cli.BoolFlag{
Name: "append",
Expand Down Expand Up @@ -106,7 +106,7 @@ var StepUpdateCommand = cli.Command{

// Post the change
err := retry.Do(func(s *retry.Stats) error {
resp, err := client.Steps.Update(cfg.Step, update)
resp, err := client.Jobs.StepUpdate(cfg.Job, update)
if resp != nil && (resp.StatusCode == 401 || resp.StatusCode == 404) {
s.Break()
}
Expand Down

0 comments on commit fd15306

Please sign in to comment.