Skip to content

Commit

Permalink
Added the "--replace" option for pipeline uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
keithpitt committed Jul 14, 2015
1 parent 40bf242 commit f04d0a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions api/pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Pipeline struct {
UUID string
Data []byte
FileName string
Replace bool
}

// Uploads the pipeline to the Buildkite Agent API. This request doesn't use JSON,
Expand All @@ -44,6 +45,9 @@ func (cs *PipelinesService) Upload(jobId string, pipeline *Pipeline) (*Response,
part, _ := createFormFileWithContentType(writer, "pipeline", fileName, contentType)
part.Write([]byte(pipeline.Data))

// Add the replace option
writer.WriteField("replace", fmt.Sprintf("%t", pipeline.Replace))

// The pipeline upload endpoint requires a way for it to uniquely
// identify this upload (because it's an idempotent endpoint). If a job
// tries to upload a pipeline that matches a previously uploaded one
Expand Down
10 changes: 8 additions & 2 deletions clicommand/pipeline_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Example:

type PipelineUploadConfig struct {
FilePath string `cli:"arg:0" label:"upload paths"`
Replace bool `cli:"replace"`
Job string `cli:"job" validate:"required"`
AgentAccessToken string `cli:"agent-access-token" validate:"required"`
Endpoint string `cli:"endpoint" validate:"required"`
Expand All @@ -43,9 +44,14 @@ type PipelineUploadConfig struct {

var PipelineUploadCommand = cli.Command{
Name: "upload",
Usage: "Upload a description of the build pipleine and change the running build",
Usage: "Uploads a description of a build pipleine adds it to the currently running build after the current job.",
Description: PipelineUploadHelpDescription,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "replace",
Usage: "Replace the rest of the existing pipeline with the steps uploaded. Jobs that are already running are not removed.",
EnvVar: "BUILDKITE_PIPELINE_REPLACE",
},
cli.StringFlag{
Name: "job",
Value: "",
Expand Down Expand Up @@ -111,7 +117,7 @@ var PipelineUploadCommand = cli.Command{

// Retry the pipeline upload a few times before giving up
err = retry.Do(func(s *retry.Stats) error {
_, err = client.Pipelines.Upload(cfg.Job, &api.Pipeline{UUID: uuid, Data: input, FileName: filename})
_, err = client.Pipelines.Upload(cfg.Job, &api.Pipeline{UUID: uuid, Data: input, FileName: filename, Replace: cfg.Replace})
if err != nil {
logger.Warn("%s (%s)", err, s)
}
Expand Down

0 comments on commit f04d0a2

Please sign in to comment.