add ability to specify last as build number for deploy
Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
parent
d8281c2cdf
commit
6206e3c117
1 changed files with 50 additions and 10 deletions
|
@ -25,6 +25,21 @@ var deployCmd = cli.Command{
|
||||||
Usage: "format output",
|
Usage: "format output",
|
||||||
Value: tmplDeployInfo,
|
Value: tmplDeployInfo,
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "branch",
|
||||||
|
Usage: "branch filter",
|
||||||
|
Value: "master",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "event",
|
||||||
|
Usage: "event filter",
|
||||||
|
Value: model.EventPush,
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "status",
|
||||||
|
Usage: "status filter",
|
||||||
|
Value: model.StatusSuccess,
|
||||||
|
},
|
||||||
cli.StringSliceFlag{
|
cli.StringSliceFlag{
|
||||||
Name: "param, p",
|
Name: "param, p",
|
||||||
Usage: "custom parameters to be injected into the job environment. Format: KEY=value",
|
Usage: "custom parameters to be injected into the job environment. Format: KEY=value",
|
||||||
|
@ -38,23 +53,48 @@ func deploy(c *cli.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
number, err := strconv.Atoi(c.Args().Get(1))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := newClient(c)
|
client, err := newClient(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
build, err := client.Build(owner, name, number)
|
branch := c.String("branch")
|
||||||
if err != nil {
|
event := c.String("event")
|
||||||
return err
|
status := c.String("status")
|
||||||
}
|
|
||||||
if build.Event == model.EventPull {
|
buildArg := c.Args().Get(1)
|
||||||
return fmt.Errorf("Cannot deploy a pull request")
|
var number int
|
||||||
|
if buildArg == "last" {
|
||||||
|
// Fetch the build number from the last build
|
||||||
|
builds, err := client.BuildList(owner, name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, build := range builds {
|
||||||
|
if branch != "" && build.Branch != branch {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if event != "" && build.Event != event {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if status != "" && build.Status != status {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if build.Number > number {
|
||||||
|
number = build.Number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if number == 0 {
|
||||||
|
return fmt.Errorf("Cannot deploy failure build")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
number, err = strconv.Atoi(buildArg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
env := c.Args().Get(2)
|
env := c.Args().Get(2)
|
||||||
if env == "" {
|
if env == "" {
|
||||||
return fmt.Errorf("Please specify the target environment (ie production)")
|
return fmt.Errorf("Please specify the target environment (ie production)")
|
||||||
|
|
Loading…
Reference in a new issue