2016-05-06 19:59:36 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
|
|
|
"github.com/drone/drone/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
var buildStartCmd = cli.Command{
|
|
|
|
Name: "start",
|
|
|
|
Usage: "start a build",
|
|
|
|
Action: func(c *cli.Context) {
|
|
|
|
if err := buildStart(c); err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "fork",
|
|
|
|
Usage: "fork the build",
|
|
|
|
},
|
2016-07-27 23:11:54 +02:00
|
|
|
cli.StringSliceFlag{
|
|
|
|
Name: "param, p",
|
|
|
|
Usage: "custom parameters to be injected into the job environment. Format: KEY=value",
|
|
|
|
},
|
2016-05-06 19:59:36 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildStart(c *cli.Context) (err error) {
|
|
|
|
repo := c.Args().First()
|
|
|
|
owner, name, err := parseRepo(repo)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
client, err := newClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-08-12 00:57:22 +02:00
|
|
|
buildArg := c.Args().Get(1)
|
|
|
|
var number int
|
|
|
|
if buildArg == "last" {
|
|
|
|
// Fetch the build number from the last build
|
|
|
|
build, err := client.BuildLast(owner, name, "")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
number = build.Number
|
|
|
|
} else {
|
|
|
|
number, err = strconv.Atoi(buildArg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-27 23:11:54 +02:00
|
|
|
params := parseKVPairs(c.StringSlice("param"))
|
|
|
|
|
2016-05-06 19:59:36 +02:00
|
|
|
var build *model.Build
|
|
|
|
if c.Bool("fork") {
|
2016-07-27 23:11:54 +02:00
|
|
|
build, err = client.BuildFork(owner, name, number, params)
|
2016-07-13 21:00:07 +02:00
|
|
|
} else {
|
2016-07-27 23:11:54 +02:00
|
|
|
build, err = client.BuildStart(owner, name, number, params)
|
2016-05-06 19:59:36 +02:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Starting build %s/%s#%d\n", owner, name, build.Number)
|
|
|
|
return nil
|
|
|
|
}
|