Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rerun pipeline job command #71

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ RELEASE_NOTE ?= "First release"
generate-client:
swagger generate client -t ./generated-client -f https://api.radix.equinor.com/swaggerui/swagger.json -A radixapi

.PHONY: release
release:
git tag -a v$(VERSION) -m "$(RELEASE_NOTE)"
git push origin v$(VERSION)
git config --global credential.helper cache
goreleaser --rm-dist

.PHONY: push
push:
docker build . -t ghcr.io/equinor/radix/rx:latest
Expand Down
7 changes: 4 additions & 3 deletions cmd/createJob.go → cmd/createPipelineJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (

// createJobCmd represents the triggering of pipeline command
var createJobCmd = &cobra.Command{
Use: "job",
Short: "Create job command",
Long: `Will be the main command for triggering pipelines.`,
Use: "pipeline-job",
Aliases: []string{"job"},
Short: "Create pipeline job command",
Long: `Will be the main command for triggering pipelines.`,
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("please specify the pipeline you want to create")
},
Expand Down
7 changes: 4 additions & 3 deletions cmd/logsJob.go → cmd/logsPipelineJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ var completedJobStatuses = []string{"Succeeded", "Failed", "Stopped"}

// logsJobCmd represents the logsJobCmd command
var logsJobCmd = &cobra.Command{
Use: "job",
Short: "Gets logs for a pipeline job",
Use: "pipeline-job",
Aliases: []string{"job"},
Short: "Gets logs for a pipeline job",
Long: `Gets and follows logs for a pipeline job.

It may take few seconds to get the log.

Example:
# Get logs for a pipeline job
rx get logs job --application radix-test --job radix-pipeline-20230323185013-ehvnz
rx get logs pipeline-job --application radix-test --job radix-pipeline-20230323185013-ehvnz
`,
RunE: func(cmd *cobra.Command, args []string) error {
appName, err := getAppNameFromConfigOrFromParameter(cmd, "application")
Expand Down
73 changes: 73 additions & 0 deletions cmd/restartPipelineJob.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright © 2023
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"errors"

"github.com/equinor/radix-cli/generated-client/client/pipeline_job"
"github.com/equinor/radix-cli/pkg/client"
"github.com/spf13/cobra"
)

// restartPipelineJobCmd represents the rerun command
var restartPipelineJobCmd = &cobra.Command{
Use: "pipeline-job",
Aliases: []string{"job"},
Short: "Restart Radix pipeline job",
Long: `Restart failed of stopped Radix pipeline job.

Example:
rx restart pipeline-job --application radix-test --job radix-pipeline-20230323185013-ehvnz
`,

RunE: func(cmd *cobra.Command, args []string) error {
appName, err := getAppNameFromConfigOrFromParameter(cmd, "application")
if err != nil {
return err
}

if appName == nil || *appName == "" {
return errors.New("application name is required")
}

jobName, _ := cmd.Flags().GetString("job")

if jobName == "" {
return errors.New("`job` is required")
}

cmd.SilenceUsage = true

apiClient, err := client.GetForCommand(cmd)
if err != nil {
return err
}

params := pipeline_job.NewRerunApplicationJobParams()
params.AppName = *appName
params.JobName = jobName

_, err = apiClient.PipelineJob.RerunApplicationJob(params, nil)
return err
},
}

func init() {
restartCmd.AddCommand(restartPipelineJobCmd)
restartPipelineJobCmd.Flags().StringP("application", "a", "", "Name of the application for the job")
restartPipelineJobCmd.Flags().StringP("job", "j", "", "The job to restart")
setContextSpecificPersistentFlags(restartPipelineJobCmd)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion generated-client/models/job.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion generated-client/models/job_summary.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading