Skip to content

Commit

Permalink
Write output file to tmp directory (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksindi committed Apr 29, 2020
1 parent 527fca1 commit 538eabf
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"io/ioutil"
"os"

"github.com/mohae/deepcopy"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -63,12 +64,20 @@ func generatePipeline(steps []interface{}, projects []Project) *Pipeline {
}

func uploadPipeline(pipeline Pipeline) {
outfile := "pipeline_output.yml"
tmpFile, err := ioutil.TempFile(os.TempDir(), "buildpipe-")
if err != nil {
log.Fatalf("Cannot create temporary file: %s\n", err)
}
defer os.Remove(tmpFile.Name())

data, err := yaml.Marshal(&pipeline)

fmt.Printf("Pipeline:\n%s", string(data))

err = ioutil.WriteFile(tmpFile.Name(), data, 0644)
if err != nil {
log.Fatalf("Error writing outfile: %s\n", err)
}
err = ioutil.WriteFile(outfile, data, 0644)
execCommand("buildkite-agent", []string{"pipeline", "upload", outfile})

execCommand("buildkite-agent", []string{"pipeline", "upload", tmpFile.Name()})
}

0 comments on commit 538eabf

Please sign in to comment.