Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
drone-cli/drone/build/build_promote.go /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
59 lines (52 sloc)
1.2 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package build | |
| import ( | |
| "os" | |
| "strconv" | |
| "text/template" | |
| "github.com/drone/drone-cli/drone/internal" | |
| "github.com/drone/funcmap" | |
| "github.com/urfave/cli" | |
| ) | |
| var buildPromoteCmd = cli.Command{ | |
| Name: "promote", | |
| Usage: "promote a build", | |
| ArgsUsage: "<repo/name> <build> <environment>", | |
| Action: buildPromote, | |
| Flags: []cli.Flag{ | |
| cli.StringSliceFlag{ | |
| Name: "param, p", | |
| Usage: "custom parameters to be injected into the job environment. Format: KEY=value", | |
| }, | |
| cli.StringFlag{ | |
| Name: "format", | |
| Usage: "format output", | |
| Value: tmplBuildInfo, | |
| }, | |
| }, | |
| } | |
| func buildPromote(c *cli.Context) (err error) { | |
| repo := c.Args().First() | |
| owner, name, err := internal.ParseRepo(repo) | |
| if err != nil { | |
| return err | |
| } | |
| number, err := strconv.Atoi(c.Args().Get(1)) | |
| if err != nil { | |
| return err | |
| } | |
| target := c.Args().Get(2) | |
| params := internal.ParseKeyPair(c.StringSlice("param")) | |
| client, err := internal.NewClient(c) | |
| if err != nil { | |
| return err | |
| } | |
| build, err := client.Promote(owner, name, number, target, params) | |
| if err != nil { | |
| return err | |
| } | |
| tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format")) | |
| if err != nil { | |
| return err | |
| } | |
| return tmpl.Execute(os.Stdout, build) | |
| } |