Skip to content

Commit 87e887b

Browse files
satrRichard87
andauthored
Added build pipeline jobs (#108)
* Added build pipeline jobs * Update cmd/createBuildPipelineJob.go Co-authored-by: Richard Hagen <[email protected]> * Update cmd/createBuildPipelineJob.go Co-authored-by: Richard Hagen <[email protected]> --------- Co-authored-by: Richard Hagen <[email protected]>
1 parent 2c7d3d3 commit 87e887b

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

cmd/createBuildPipelineJob.go

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright © 2023
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cmd
16+
17+
import (
18+
"errors"
19+
20+
"github.com/equinor/radix-cli/generated-client/client/application"
21+
"github.com/equinor/radix-cli/generated-client/models"
22+
"github.com/equinor/radix-cli/pkg/client"
23+
"github.com/equinor/radix-cli/pkg/config"
24+
"github.com/equinor/radix-cli/pkg/flagnames"
25+
"github.com/equinor/radix-cli/pkg/utils/completion"
26+
log "github.com/sirupsen/logrus"
27+
"github.com/spf13/cobra"
28+
)
29+
30+
// createBuildPipelineJobCmd represents the createBuildPipelineJob command
31+
var createBuildPipelineJobCmd = &cobra.Command{
32+
Use: "build",
33+
Short: "Will trigger build of a Radix application",
34+
Long: `Triggers build of Radix application, for branches that are mapped to a environment in the Radix config`,
35+
RunE: func(cmd *cobra.Command, args []string) error {
36+
appName, err := config.GetAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
37+
if err != nil {
38+
return err
39+
}
40+
if appName == "" {
41+
return errors.New("application name is required")
42+
}
43+
branch, _ := cmd.Flags().GetString(flagnames.Branch)
44+
follow, _ := cmd.Flags().GetBool(flagnames.Follow)
45+
46+
cmd.SilenceUsage = true
47+
48+
apiClient, err := client.GetForCommand(cmd)
49+
if err != nil {
50+
return err
51+
}
52+
triggerDeployParams := application.NewTriggerPipelineBuildParams()
53+
triggerDeployParams.SetAppName(appName)
54+
triggerDeployParams.SetPipelineParametersBuild(&models.PipelineParametersBuild{
55+
Branch: branch,
56+
})
57+
newJob, err := apiClient.Application.TriggerPipelineBuild(triggerDeployParams, nil)
58+
if err != nil {
59+
return err
60+
}
61+
62+
jobName := newJob.GetPayload().Name
63+
log.Infof("Build pipeline job triggered with the name %s\n", jobName)
64+
if !follow {
65+
return nil
66+
}
67+
68+
return getLogsJob(cmd, apiClient, appName, jobName)
69+
},
70+
}
71+
72+
func init() {
73+
createJobCmd.AddCommand(createBuildPipelineJobCmd)
74+
createBuildPipelineJobCmd.Flags().StringP(flagnames.Branch, "b", "master", "Branch to build from")
75+
createBuildPipelineJobCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application to build")
76+
createBuildPipelineJobCmd.Flags().BoolP(flagnames.Follow, "f", false, "Follow build")
77+
if err := createBuildPipelineJobCmd.MarkFlagRequired(flagnames.Branch); err != nil {
78+
log.Fatalf("Error during command initialization: %v", err)
79+
}
80+
_ = createPromotePipelineJobCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ApplicationCompletion)
81+
setContextSpecificPersistentFlags(createBuildPipelineJobCmd)
82+
}

0 commit comments

Comments
 (0)