2017-04-29 17:03:45 +00:00
|
|
|
package build
|
2016-05-06 17:59:36 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
2017-04-29 17:03:45 +00:00
|
|
|
"github.com/drone/drone/drone/internal"
|
2016-05-06 17:59:36 +00:00
|
|
|
"github.com/drone/drone/model"
|
2017-03-16 10:14:02 +00:00
|
|
|
"github.com/urfave/cli"
|
2016-05-06 17:59:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var buildStartCmd = cli.Command{
|
2017-03-16 10:14:02 +00:00
|
|
|
Name: "start",
|
|
|
|
Usage: "start a build",
|
|
|
|
Action: buildStart,
|
2016-05-06 17:59:36 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "fork",
|
|
|
|
Usage: "fork the build",
|
|
|
|
},
|
2016-07-27 21:11:54 +00:00
|
|
|
cli.StringSliceFlag{
|
|
|
|
Name: "param, p",
|
|
|
|
Usage: "custom parameters to be injected into the job environment. Format: KEY=value",
|
|
|
|
},
|
2016-05-06 17:59:36 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildStart(c *cli.Context) (err error) {
|
|
|
|
repo := c.Args().First()
|
2017-04-29 17:03:45 +00:00
|
|
|
owner, name, err := internal.ParseRepo(repo)
|
2016-05-06 17:59:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-04-29 17:03:45 +00:00
|
|
|
client, err := internal.NewClient(c)
|
2016-05-06 17:59:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-08-11 22:57:22 +00: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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-29 17:03:45 +00:00
|
|
|
params := internal.ParseKeyPair(c.StringSlice("param"))
|
2016-07-27 21:11:54 +00:00
|
|
|
|
2016-05-06 17:59:36 +00:00
|
|
|
var build *model.Build
|
|
|
|
if c.Bool("fork") {
|
2016-07-27 21:11:54 +00:00
|
|
|
build, err = client.BuildFork(owner, name, number, params)
|
2016-07-13 19:00:07 +00:00
|
|
|
} else {
|
2016-07-27 21:11:54 +00:00
|
|
|
build, err = client.BuildStart(owner, name, number, params)
|
2016-05-06 17:59:36 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Starting build %s/%s#%d\n", owner, name, build.Number)
|
|
|
|
return nil
|
|
|
|
}
|