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

New JFrog Pipelines commands #1766

Merged
merged 25 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5ef67e7
Added pipelines run status and trigger run
bhanurp Nov 23, 2022
aea58a8
Moved pipelines commands to jfrog-cli-core
bhanurp Nov 24, 2022
2d21db6
Updated with multi branch details
bhanurp Dec 14, 2022
7271a60
Updated command pipelines short hand
bhanurp Dec 20, 2022
52a6ce1
Updated command pipelines short hand
bhanurp Dec 20, 2022
0a4f69c
Fixed possible review comments
bhanurp Dec 22, 2022
2abcb6d
Updated pipelines command
bhanurp Jan 1, 2023
9ddec8a
Updated cli core revision
bhanurp Jan 1, 2023
36c12ff
Merge branch 'dev' into v2
bhanurp Jan 2, 2023
7ed4c6b
Correct dependency conflict
bhanurp Jan 2, 2023
3e407b4
Updated logs and comments starting letter to upper case
bhanurp Jan 4, 2023
eb3168c
Updated pipelines command to pl
bhanurp Jan 4, 2023
b7af659
Updated with camel case
bhanurp Jan 4, 2023
6e1de6e
Removed notification feature
bhanurp Jan 5, 2023
72c4228
Updated pielines cli with docs
bhanurp Jan 13, 2023
37d2cc5
Updated to use commands exec
bhanurp Jan 14, 2023
2dc02ef
Updated comments to start with capital letter
bhanurp Jan 14, 2023
237b8cb
Added pipeline commands
bhanurp Jan 17, 2023
7e5d9d1
Updated pipelines commands arguments help doc
bhanurp Jan 17, 2023
2f5de1a
Updated pipelines commands arguments help doc
bhanurp Jan 17, 2023
31a0d2a
Opted to use err for error variable for possible redeclaration
bhanurp Jan 19, 2023
9cdf65e
Merge branch 'dev' into v2
bhanurp Jan 24, 2023
b7f2751
Relative changes to cli-core
bhanurp Jan 24, 2023
d8324ad
Refactored pipeline commands to cli
bhanurp Jan 26, 2023
31851a2
Changed sync status command to sync-status
bhanurp Jan 26, 2023
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
11 changes: 11 additions & 0 deletions docs/pipelines/status/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package status

var Usage = []string{"pl status"}

func GetDescription() string {
return "Fetch latest pipeline run status."
bhanurp marked this conversation as resolved.
Show resolved Hide resolved
}

func GetArguments() string {
return ` `
}
15 changes: 15 additions & 0 deletions docs/pipelines/sync/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package sync

var Usage = []string{"pl sync <repository name>"}
bhanurp marked this conversation as resolved.
Show resolved Hide resolved

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
`
}
11 changes: 11 additions & 0 deletions docs/pipelines/syncstatus/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package syncstatus

var Usage = []string{"pl syncstatus"}
bhanurp marked this conversation as resolved.
Show resolved Hide resolved

func GetDescription() string {
return "Fetch pipeline resource sync status."
}

func GetArguments() string {
return ` `
}
14 changes: 14 additions & 0 deletions docs/pipelines/trigger/help.go
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 manual run
branch name
branch name to trigger manual run`
}
11 changes: 11 additions & 0 deletions docs/pipelines/version/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package version

var Usage = []string{"pl version"}

func GetDescription() string {
return "Get pipelines version."
bhanurp marked this conversation as resolved.
Show resolved Hide resolved
}

func GetArguments() string {
return ` `
}
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.2-0.20221107114147-4a1ad939c80e
// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.1-0.20221031115821-41443331f630

replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.24.6-0.20221227065543-64d39165803a
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/bhanurp/jfrog-cli-core/v2 v2.24.4-0.20230114051843-494488f7bc90

replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.26.1-0.20221228094004-365894ac6254
// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.26.1-0.20221228094004-365894ac6254

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.2.5-0.20221107113836-a4c9225c690e

replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.24.6-0.20221229104544-1cf7ece4449c
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bhanurp/jfrog-cli-core/v2 v2.24.4-0.20230114051843-494488f7bc90 h1:R0ruMaCKNWDWaLZQAlO9PlpBIS8Y7ES3pB57sohkELg=
github.com/bhanurp/jfrog-cli-core/v2 v2.24.4-0.20230114051843-494488f7bc90/go.mod h1:Xevv0gjWrbROvC2klNEx34LuQrfYEn+VY3GEENmPIqc=
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
Expand Down Expand Up @@ -531,10 +533,8 @@ github.com/jfrog/build-info-go v1.8.4 h1:OisVjARmaXzXV9IuGvNJzB0XL8a6RVSrR2/zOsR
github.com/jfrog/build-info-go v1.8.4/go.mod h1:iSTj26qEX3eUtyAGMH0qKsW4WJT+MceYxLWP9FfiAq4=
github.com/jfrog/gofrog v1.2.5 h1:jCgJC0iGQ8bU7jCC+YEFJTNINyngApIrhd8BjZAVRIE=
github.com/jfrog/gofrog v1.2.5/go.mod h1:o00tSRff6IapTgaCMuX1Cs9MH08Y1JqnsKgRtx91Gc4=
github.com/jfrog/jfrog-cli-core/v2 v2.26.1-0.20221228094004-365894ac6254 h1:QAqiiiDU2hkAMIFaQCegIIJFjbV8Ga3anV4UJAB+ZYQ=
github.com/jfrog/jfrog-cli-core/v2 v2.26.1-0.20221228094004-365894ac6254/go.mod h1:l0yqFZ91rgaip+naVdcPEmtz0TmndUZy7KjMlj0zR2k=
github.com/jfrog/jfrog-client-go v1.24.6-0.20221227065543-64d39165803a h1:9ni92q7WcMDTGtvH/GpQ93+6k16qWticYwKvXw7HLuM=
github.com/jfrog/jfrog-client-go v1.24.6-0.20221227065543-64d39165803a/go.mod h1:jCif5JAnF3RZ+ldzJ+0jX1OCcrXzJVjWHENVGyiy6nI=
github.com/jfrog/jfrog-client-go v1.24.6-0.20221229104544-1cf7ece4449c h1:1ZS7CWw0/W5SKyjbQm5ZhBzMG2slGqMqtiU8t9tEEJA=
github.com/jfrog/jfrog-client-go v1.24.6-0.20221229104544-1cf7ece4449c/go.mod h1:jCif5JAnF3RZ+ldzJ+0jX1OCcrXzJVjWHENVGyiy6nI=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.0.0-20160803190731-bd40a432e4c7/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/joefitzgerald/rainbow-reporter v0.1.0/go.mod h1:481CNgqmVHQZzdIbN52CupLJyoVwB10FQ/IQlF1pdL8=
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/jfrog/jfrog-cli/general/envsetup"
"github.com/jfrog/jfrog-cli/general/project"
"github.com/jfrog/jfrog-cli/missioncontrol"
"github.com/jfrog/jfrog-cli/pipelines"
"github.com/jfrog/jfrog-cli/plugins"
"github.com/jfrog/jfrog-cli/plugins/utils"
"github.com/jfrog/jfrog-cli/scan"
Expand Down Expand Up @@ -174,6 +175,12 @@ func getCommands() []cli.Command {
Subcommands: distribution.GetCommands(),
Category: otherCategory,
},
{
Name: cliutils.CmdPipelines,
Usage: "JFrog Pipelines commands.",
Subcommands: pipelines.GetCommands(),
Category: otherCategory,
},
{
Name: cliutils.CmdCompletion,
Usage: "Generate autocomplete scripts.",
Expand Down
83 changes: 83 additions & 0 deletions pipelines/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package pipelines

import (
corecommon "github.com/jfrog/jfrog-cli-core/v2/docs/common"
"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"
"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),
UsageText: status.GetArguments(),
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),
UsageText: version.GetArguments(),
ArgsUsage: common.CreateEnvVars(),
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: "syncstatus",
bhanurp marked this conversation as resolved.
Show resolved Hide resolved
Flags: cliutils.GetCommandFlags(cliutils.SyncStatus),
Aliases: []string{"ss"},
Usage: syncstatus.GetDescription(),
HelpName: corecommon.CreateUsage("pl syncstatus", syncstatus.GetDescription(), syncstatus.Usage),
bhanurp marked this conversation as resolved.
Show resolved Hide resolved
UsageText: syncstatus.GetArguments(),
ArgsUsage: common.CreateEnvVars(),
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return getSyncPipelineResourcesStatus(c)
},
},
})
}
bhanurp marked this conversation as resolved.
Show resolved Hide resolved
38 changes: 38 additions & 0 deletions pipelines/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package pipelines

import (
"fmt"
coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli/utils/cliutils"
clientlog "github.com/jfrog/jfrog-client-go/utils/log"
"github.com/urfave/cli"
"strconv"
)

// getMultiBranch parses multibranch flag to bool
func getMultiBranch(c *cli.Context) bool {
multiBranch := c.String("multiBranch")
if multiBranch == "" {
return true
} else {
bhanurp marked this conversation as resolved.
Show resolved Hide resolved
multiBranch, err := strconv.ParseBool(multiBranch)
if err != nil {
clientlog.Warn("MultiBranch flag can parse these values: [1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False]")
clientlog.Warn("Setting multiBranch to true")
return true
}
return multiBranch
}
}

// 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
}
33 changes: 33 additions & 0 deletions pipelines/runstatus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package pipelines

import (
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
status "github.com/jfrog/jfrog-cli-core/v2/pipelines/commands"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
clientlog "github.com/jfrog/jfrog-client-go/utils/log"
"github.com/urfave/cli"
)

// fetchLatestPipelineRunStatus fetch pipeline run status and filter from pipeline-name and branch flags
bhanurp marked this conversation as resolved.
Show resolved Hide resolved
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, servErr := createPipelinesDetailsByFlags(c)
if servErr != nil {
return servErr
}
statusCommand := status.NewStatusCommand()
statusCommand.SetBranch(branch).
SetPipeline(pipName).
SetNotify(notify).
SetMultiBranch(multiBranch)

// Set server details
statusCommand.SetServerDetails(serviceDetails)
return commands.Exec(statusCommand)
}
47 changes: 47 additions & 0 deletions pipelines/sync.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package pipelines

import (
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
syncPipeRes "github.com/jfrog/jfrog-cli-core/v2/pipelines/commands"
clientlog "github.com/jfrog/jfrog-client-go/utils/log"
"github.com/urfave/cli"
)

// 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)
bhanurp marked this conversation as resolved.
Show resolved Hide resolved
serviceDetails, servErr := createPipelinesDetailsByFlags(c)
if servErr != nil {
return servErr
}

// Create new sync command and add filters
syncCommand := syncPipeRes.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, servErr := createPipelinesDetailsByFlags(c)
if servErr != nil {
return servErr
}

// Create sync status command and add filter params
syncStatusCommand := syncPipeRes.NewSyncStatusCommand()
syncStatusCommand.SetBranch(branch)
syncStatusCommand.SetRepoPath(repository)
syncStatusCommand.SetServerDetails(serviceDetails)
return commands.Exec(syncStatusCommand)
}
18 changes: 18 additions & 0 deletions pipelines/systeminfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pipelines

import (
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
status "github.com/jfrog/jfrog-cli-core/v2/pipelines/commands"
"github.com/urfave/cli"
)

// getVersion version command handler
func getVersion(c *cli.Context) error {
serviceDetails, servErr := createPipelinesDetailsByFlags(c)
if servErr != nil {
return servErr
}
versionCommand := status.NewVersionCommand()
versionCommand.SetServerDetails(serviceDetails)
return commands.Exec(versionCommand)
}
33 changes: 33 additions & 0 deletions pipelines/triggerrun.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package pipelines

import (
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
status "github.com/jfrog/jfrog-cli-core/v2/pipelines/commands"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
clientlog "github.com/jfrog/jfrog-client-go/utils/log"
"github.com/urfave/cli"
)

// 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 pipelineName", pipelineName, "for branch ", branch)

// Get service config details
serviceDetails, servErr := createPipelinesDetailsByFlags(c)
if servErr != nil {
return servErr
}

// Trigger a pipeline run using branch name and pipeline name
triggerCommand := status.NewTriggerCommand()
triggerCommand.SetBranch(branch).
SetPipeline(pipelineName).
SetServerDetails(serviceDetails).
SetMultiBranch(multiBranch)
return commands.Exec(triggerCommand)
}
1 change: 1 addition & 0 deletions utils/cliutils/cli_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
CmdConfig = "config"
CmdOptions = "options"
CmdProject = "project"
CmdPipelines = "pl"

// Download
DownloadMinSplitKb = 5120
Expand Down
Loading