-
Notifications
You must be signed in to change notification settings - Fork 1
/
trigger-build.go
57 lines (48 loc) · 1.32 KB
/
trigger-build.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package pipelines
import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/cycloidio/cycloid-cli/cmd/cycloid/common"
"github.com/cycloidio/cycloid-cli/cmd/cycloid/internal"
"github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware"
)
func NewTriggerBuildCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "trigger-build",
Example: `
# trigger a pipeline build for 'my-job'
cy --org my-org pp trigger-build --project my-project --env my-env --job my-job
`,
Short: "trigger a pipeline build",
RunE: createBuild,
PreRunE: internal.CheckAPIAndCLIVersion,
}
common.RequiredPersistentFlag(common.WithFlagProject, cmd)
common.RequiredPersistentFlag(common.WithFlagEnv, cmd)
common.RequiredFlag(WithFlagJob, cmd)
return cmd
}
func createBuild(cmd *cobra.Command, args []string) error {
api := common.NewAPI()
m := middleware.NewMiddleware(api)
org, err := cmd.Flags().GetString("org")
if err != nil {
return err
}
project, err := cmd.Flags().GetString("project")
if err != nil {
return err
}
env, err := cmd.Flags().GetString("env")
if err != nil {
return err
}
job, err := cmd.Flags().GetString("job")
if err != nil {
return err
}
if err := m.TriggerPipelineBuild(org, project, env, job); err != nil {
return errors.Wrap(err, "unable to trigger pipeline build")
}
return nil
}