-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New JFrog Pipelines commands (#1766)
- Loading branch information
Showing
11 changed files
with
318 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package status | ||
|
||
var Usage = []string{"pl status"} | ||
|
||
func GetDescription() string { | ||
return "Fetch the latest pipeline run status." | ||
} |
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,14 @@ | ||
package sync | ||
|
||
var Usage = []string{"pl sync"} | ||
|
||
func GetDescription() string { | ||
return "Sync a pipeline resource." | ||
} | ||
|
||
func GetArguments() string { | ||
return ` repository name | ||
Full repository name of the pipeline resource. | ||
branch name | ||
Branch name to trigger sync on.` | ||
} |
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,7 @@ | ||
package syncstatus | ||
|
||
var Usage = []string{"pl sync-status"} | ||
|
||
func GetDescription() string { | ||
return "Fetch pipeline resource sync status." | ||
} |
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,14 @@ | ||
package trigger | ||
|
||
var Usage = []string{"pl trigger"} | ||
|
||
func GetDescription() string { | ||
return "Trigger a manual pipeline run." | ||
} | ||
|
||
func GetArguments() string { | ||
return ` pipeline name | ||
Pipeline name to trigger the manual run on. | ||
branch name | ||
Branch name to trigger the manual run on.` | ||
} |
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,7 @@ | ||
package version | ||
|
||
var Usage = []string{"pl version"} | ||
|
||
func GetDescription() string { | ||
return "Show the version of JFrog Pipelines." | ||
} |
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,201 @@ | ||
package pipelines | ||
|
||
import ( | ||
"fmt" | ||
"github.com/jfrog/jfrog-cli-core/v2/common/commands" | ||
corecommon "github.com/jfrog/jfrog-cli-core/v2/docs/common" | ||
pipelines "github.com/jfrog/jfrog-cli-core/v2/pipelines/commands" | ||
coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config" | ||
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" | ||
"github.com/jfrog/jfrog-cli/docs/common" | ||
"github.com/jfrog/jfrog-cli/docs/pipelines/status" | ||
"github.com/jfrog/jfrog-cli/docs/pipelines/sync" | ||
"github.com/jfrog/jfrog-cli/docs/pipelines/syncstatus" | ||
"github.com/jfrog/jfrog-cli/docs/pipelines/trigger" | ||
"github.com/jfrog/jfrog-cli/docs/pipelines/version" | ||
|
||
"github.com/jfrog/jfrog-cli/utils/cliutils" | ||
clientlog "github.com/jfrog/jfrog-client-go/utils/log" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
func GetCommands() []cli.Command { | ||
return cliutils.GetSortedCommands(cli.CommandsByName{ | ||
{ | ||
Name: "status", | ||
Flags: cliutils.GetCommandFlags(cliutils.Status), | ||
Aliases: []string{"s"}, | ||
Usage: status.GetDescription(), | ||
HelpName: corecommon.CreateUsage("pl status", status.GetDescription(), status.Usage), | ||
ArgsUsage: common.CreateEnvVars(), | ||
BashComplete: corecommon.CreateBashCompletionFunc(), | ||
Action: func(c *cli.Context) error { | ||
return fetchLatestPipelineRunStatus(c) | ||
}, | ||
}, | ||
{ | ||
Name: "trigger", | ||
Flags: cliutils.GetCommandFlags(cliutils.Trigger), | ||
Aliases: []string{"t"}, | ||
Usage: trigger.GetDescription(), | ||
HelpName: corecommon.CreateUsage("pl trigger", trigger.GetDescription(), trigger.Usage), | ||
UsageText: trigger.GetArguments(), | ||
ArgsUsage: common.CreateEnvVars(), | ||
BashComplete: corecommon.CreateBashCompletionFunc(), | ||
Action: func(c *cli.Context) error { | ||
return triggerNewRun(c) | ||
}, | ||
}, | ||
{ | ||
Name: "version", | ||
Flags: cliutils.GetCommandFlags(cliutils.Version), | ||
Aliases: []string{"v"}, | ||
Usage: version.GetDescription(), | ||
HelpName: corecommon.CreateUsage("pl version", version.GetDescription(), version.Usage), | ||
BashComplete: corecommon.CreateBashCompletionFunc(), | ||
Action: func(c *cli.Context) error { | ||
return getVersion(c) | ||
}, | ||
}, | ||
{ | ||
Name: "sync", | ||
Flags: cliutils.GetCommandFlags(cliutils.Sync), | ||
Aliases: []string{"sy"}, | ||
Usage: sync.GetDescription(), | ||
HelpName: corecommon.CreateUsage("pl sync", sync.GetDescription(), sync.Usage), | ||
UsageText: sync.GetArguments(), | ||
ArgsUsage: common.CreateEnvVars(), | ||
BashComplete: corecommon.CreateBashCompletionFunc(), | ||
Action: func(c *cli.Context) error { | ||
return syncPipelineResources(c) | ||
}, | ||
}, | ||
{ | ||
Name: "sync-status", | ||
Flags: cliutils.GetCommandFlags(cliutils.SyncStatus), | ||
Aliases: []string{"ss"}, | ||
Usage: syncstatus.GetDescription(), | ||
HelpName: corecommon.CreateUsage("pl sync-status", syncstatus.GetDescription(), syncstatus.Usage), | ||
ArgsUsage: common.CreateEnvVars(), | ||
BashComplete: corecommon.CreateBashCompletionFunc(), | ||
Action: func(c *cli.Context) error { | ||
return getSyncPipelineResourcesStatus(c) | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
// getMultiBranch parses singleBranch flag and computes whether multiBranch is set to true/false | ||
func getMultiBranch(c *cli.Context) bool { | ||
return !c.Bool("single-branch") | ||
} | ||
|
||
// createPipelinesDetailsByFlags creates pipelines configuration details | ||
func createPipelinesDetailsByFlags(c *cli.Context) (*coreConfig.ServerDetails, error) { | ||
plDetails, err := cliutils.CreateServerDetailsWithConfigOffer(c, true, cliutils.CmdPipelines) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if plDetails.DistributionUrl == "" { | ||
return nil, fmt.Errorf("the --pipelines-url option is mandatory") | ||
} | ||
return plDetails, nil | ||
} | ||
|
||
// fetchLatestPipelineRunStatus fetches pipeline run status and filters from pipeline-name and branch flags | ||
func fetchLatestPipelineRunStatus(c *cli.Context) error { | ||
clientlog.Info(coreutils.PrintTitle("Fetching pipeline run status")) | ||
|
||
// Read flags for status command | ||
pipName := c.String("pipeline-name") | ||
notify := c.Bool("monitor") | ||
branch := c.String("branch") | ||
multiBranch := getMultiBranch(c) | ||
serviceDetails, err := createPipelinesDetailsByFlags(c) | ||
if err != nil { | ||
return err | ||
} | ||
statusCommand := pipelines.NewStatusCommand() | ||
statusCommand.SetBranch(branch). | ||
SetPipeline(pipName). | ||
SetNotify(notify). | ||
SetMultiBranch(multiBranch) | ||
|
||
// Set server details | ||
statusCommand.SetServerDetails(serviceDetails) | ||
return commands.Exec(statusCommand) | ||
} | ||
|
||
// syncPipelineResources sync pipelines resource | ||
func syncPipelineResources(c *cli.Context) error { | ||
// Get arguments repository name and branch name | ||
repository := c.Args().Get(0) | ||
branch := c.Args().Get(1) | ||
clientlog.Info("Triggering pipeline sync on repository:", repository, "branch:", branch) | ||
serviceDetails, err := createPipelinesDetailsByFlags(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Create new sync command and add filters | ||
syncCommand := pipelines.NewSyncCommand() | ||
syncCommand.SetBranch(branch) | ||
syncCommand.SetRepositoryFullName(repository) | ||
syncCommand.SetServerDetails(serviceDetails) | ||
return commands.Exec(syncCommand) | ||
} | ||
|
||
// getSyncPipelineResourcesStatus fetch sync status for a given repository path and branch name | ||
func getSyncPipelineResourcesStatus(c *cli.Context) error { | ||
branch := c.String("branch") | ||
repository := c.String("repository") | ||
clientlog.Info("Fetching pipeline sync status on repository:", repository, "branch:", branch) | ||
|
||
// Fetch service details for authentication | ||
serviceDetails, err := createPipelinesDetailsByFlags(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Create sync status command and add filter params | ||
syncStatusCommand := pipelines.NewSyncStatusCommand() | ||
syncStatusCommand.SetBranch(branch) | ||
syncStatusCommand.SetRepoPath(repository) | ||
syncStatusCommand.SetServerDetails(serviceDetails) | ||
return commands.Exec(syncStatusCommand) | ||
} | ||
|
||
// getVersion version command handler | ||
func getVersion(c *cli.Context) error { | ||
serviceDetails, err := createPipelinesDetailsByFlags(c) | ||
if err != nil { | ||
return err | ||
} | ||
versionCommand := pipelines.NewVersionCommand() | ||
versionCommand.SetServerDetails(serviceDetails) | ||
return commands.Exec(versionCommand) | ||
} | ||
|
||
// triggerNewRun triggers a new run for supplied flag values | ||
func triggerNewRun(c *cli.Context) error { | ||
// Read arguments pipeline name and branch to trigger pipeline run | ||
pipelineName := c.Args().Get(0) | ||
branch := c.Args().Get(1) | ||
multiBranch := getMultiBranch(c) | ||
coreutils.PrintTitle("Triggering pipeline run ") | ||
clientlog.Info("Triggering on pipeline:", pipelineName, "for branch:", branch) | ||
|
||
// Get service config details | ||
serviceDetails, err := createPipelinesDetailsByFlags(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Trigger a pipeline run using branch name and pipeline name | ||
triggerCommand := pipelines.NewTriggerCommand() | ||
triggerCommand.SetBranch(branch). | ||
SetPipelineName(pipelineName). | ||
SetServerDetails(serviceDetails). | ||
SetMultiBranch(multiBranch) | ||
return commands.Exec(triggerCommand) | ||
} |
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