-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for subcommand run/runfailed jobs and run/cancel stages o…
…f GoCD pipeline
- Loading branch information
1 parent
ff8c9a6
commit 855ae28
Showing
17 changed files
with
398 additions
and
23 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package cmd | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
func registerStageCommand() *cobra.Command { | ||
jobsCommand := &cobra.Command{ | ||
Use: "stage", | ||
Short: "Command to operate on stages of a pipeline present in GoCD", | ||
Long: `Command leverages GoCD job apis' | ||
[https://api.gocd.org/current/#stage-instancess] to | ||
CANCEL/RUN stage of specific pipeline present GoCD`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if err := cmd.Usage(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
jobsCommand.SetUsageTemplate(getUsageTemplate()) | ||
|
||
jobsCommand.AddCommand(getCancelStageCommand()) | ||
jobsCommand.AddCommand(getRunStageCommand()) | ||
|
||
for _, command := range jobsCommand.Commands() { | ||
command.SilenceUsage = true | ||
} | ||
|
||
return jobsCommand | ||
} | ||
|
||
func getCancelStageCommand() *cobra.Command { | ||
getCancelStageCmd := &cobra.Command{ | ||
Use: "cancel", | ||
Short: "Command to cancel specific stage of a pipeline present in GoCD [https://api.gocd.org/current/#run-failed-jobs]", | ||
Args: cobra.NoArgs, | ||
PreRunE: setCLIClient, | ||
Example: `gocd-cli stage cancel --pipeline myPipeline --pipeline-counter 2 --stage myStage --stage-counter 3`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
response, err := client.CancelStage(stageConfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return cliRenderer.Render(response) | ||
}, | ||
} | ||
|
||
registerJobsNStageFlags(getCancelStageCmd) | ||
|
||
return getCancelStageCmd | ||
} | ||
|
||
func getRunStageCommand() *cobra.Command { | ||
getScheduledJobsCmd := &cobra.Command{ | ||
Use: "run", | ||
Short: "Command to run a stage from a selected pipeline present in GoCD [https://api.gocd.org/current/#run-selected-jobs]", | ||
Args: cobra.NoArgs, | ||
PreRunE: setCLIClient, | ||
Example: `gocd-cli stage run --pipeline myPipeline --pipeline-counter 2 --stage myStage --stage-counter 3 --job job1 --job job2`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
response, err := client.RunStage(stageConfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return cliRenderer.Render(response) | ||
}, | ||
} | ||
|
||
registerJobsNStageFlags(getScheduledJobsCmd) | ||
|
||
return getScheduledJobsCmd | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
## gocd-cli job run-failed | ||
|
||
Command to run failed jobs of specific pipelines in GoCD [https://api.gocd.org/current/#run-failed-jobs] | ||
|
||
``` | ||
gocd-cli job run-failed [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
gocd-cli job run --pipeline myPipeline --pipeline-counter 2 --stage myStage --stage-counter 3 | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for run-failed | ||
--job strings list of jobs that should be triggered | ||
--pipeline string pipeline name from which the jobs/stage to be triggered | ||
--pipeline-counter string instance of the pipeline that should be considered | ||
--stage string stage name that should to be operated | ||
--stage-counter string instance of the stage that should be considered | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-t, --auth-token string token to authenticate with GoCD server, should not be co-used with basic auth (username/password) | ||
--ca-file-path string path to file containing CA cert used to authenticate GoCD server, if you have one | ||
--from-file string file containing configurations of objects that needs to be created in GoCD, config-repo/pipeline-group/environment and etc. | ||
--json enable this to Render output in JSON format | ||
-l, --log-level string log level for gocd cli, log levels supported by [https://github.com/sirupsen/logrus] will work (default "info") | ||
--no-color enable this to Render output in YAML format | ||
-p, --password string password to authenticate with GoCD server | ||
-q, --query string query to filter the results, ex: '.material.attributes.type | id eq git'. this uses library gojsonq beneath | ||
more queries can be found here https://github.com/thedevsaddam/gojsonq/wiki/Queries | ||
--server-url string GoCD server URL base path (default "http://localhost:8153/go") | ||
--skip-cache-config if enabled locally save auth configs would not be used to authenticate GoCD server (path: $HOME/.gocd/auth_config.yaml) | ||
--to-file string file to which the output needs to be written to | ||
-u, --username string username to authenticate with GoCD server | ||
--yaml enable this to Render output in YAML format | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [gocd-cli job](gocd-cli_job.md) - Command to operate on jobs present in GoCD | ||
|
||
###### Auto generated by spf13/cobra on 17-Jul-2023 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
## gocd-cli job run | ||
|
||
Command to run list of jobs those are part of selected pipeline in GoCD [https://api.gocd.org/current/#run-selected-jobs] | ||
|
||
``` | ||
gocd-cli job run [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
gocd-cli job run --pipeline myPipeline --pipeline-counter 2 --stage myStage --stage-counter 3 --job job1 --job job2 | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for run | ||
--job strings list of jobs that should be triggered | ||
--pipeline string pipeline name from which the jobs/stage to be triggered | ||
--pipeline-counter string instance of the pipeline that should be considered | ||
--stage string stage name that should to be operated | ||
--stage-counter string instance of the stage that should be considered | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-t, --auth-token string token to authenticate with GoCD server, should not be co-used with basic auth (username/password) | ||
--ca-file-path string path to file containing CA cert used to authenticate GoCD server, if you have one | ||
--from-file string file containing configurations of objects that needs to be created in GoCD, config-repo/pipeline-group/environment and etc. | ||
--json enable this to Render output in JSON format | ||
-l, --log-level string log level for gocd cli, log levels supported by [https://github.com/sirupsen/logrus] will work (default "info") | ||
--no-color enable this to Render output in YAML format | ||
-p, --password string password to authenticate with GoCD server | ||
-q, --query string query to filter the results, ex: '.material.attributes.type | id eq git'. this uses library gojsonq beneath | ||
more queries can be found here https://github.com/thedevsaddam/gojsonq/wiki/Queries | ||
--server-url string GoCD server URL base path (default "http://localhost:8153/go") | ||
--skip-cache-config if enabled locally save auth configs would not be used to authenticate GoCD server (path: $HOME/.gocd/auth_config.yaml) | ||
--to-file string file to which the output needs to be written to | ||
-u, --username string username to authenticate with GoCD server | ||
--yaml enable this to Render output in YAML format | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [gocd-cli job](gocd-cli_job.md) - Command to operate on jobs present in GoCD | ||
|
||
###### Auto generated by spf13/cobra on 17-Jul-2023 |
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
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
Oops, something went wrong.