pipeline

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CancelPipelineRunCmd = &cobra.Command{
	Use:   "cancel <runId>",
	Short: "Cancel a pipeline run",
	Args:  cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		var subscriptionId, resourceGroupName, factoryName = GetArgs(cmd, args)
		var runId = args[0]

		clientFactory, err := GetClientFactory(subscriptionId)
		if err != nil {
			log.Fatalf("failed to create client: %v", err)
		}

		recursive, err := cmd.Flags().GetBool("recursive")
		if err != nil {
			log.Fatalf("failed to get the value of the flag: %v", err)
		}

		ctx := context.Background()
		_, err = clientFactory.NewPipelineRunsClient().Cancel(ctx, resourceGroupName, factoryName, runId, &armdatafactory.PipelineRunsClientCancelOptions{IsRecursive: &recursive})
		if err != nil {
			log.Fatalf("failed to finish the request: %v", err)
		} else {
			log.Print("pipeline run canceled successfully")
		}
	},
}

getCmd represents the get command

View Source
var ListPipelineCmd = &cobra.Command{
	Use:   "list",
	Short: "List all pipelines from a factory",
	Run: func(cmd *cobra.Command, args []string) {
		var subscriptionId, resourceGroupName, factoryName = GetArgs(cmd, args)

		clientFactory, err := GetClientFactory(subscriptionId)
		if err != nil {
			log.Fatalf("failed to create client: %v", err)
		}

		ctx := context.Background()
		pager := clientFactory.NewPipelinesClient().NewListByFactoryPager(resourceGroupName, factoryName, nil)
		for pager.More() {
			page, err := pager.NextPage(ctx)
			if err != nil {
				log.Fatalf("failed to advance page: %v", err)
			}
			for _, v := range page.Value {
				fmt.Printf("\t%v\n", *v.Name)
			}
		}
	},
}

getCmd represents the get command

View Source
var PipelineCmd = &cobra.Command{
	Use: "pipeline [command]",
	Run: func(cmd *cobra.Command, args []string) {

		fmt.Println("param needs a subcommand. Available subcommands are:")
		for _, cmd := range cmd.Commands() {
			fmt.Printf("  %s\n", cmd.Use)
		}
	},
}

triggerCmd represents the trigger command

View Source
var RunPipelineCmd = &cobra.Command{
	Use:   "run <pipelineName> [parameters]",
	Short: "Creates a run of a pipeline.",
	Long: `Creates a run of a pipeline.
For example:
  adf-cli pipeline run myPipeline "{\"param1\": \"value1\", \"param2\": \"value2\"}"
	`,
	Args: cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		var subscriptionId, resourceGroupName, factoryName = GetArgs(cmd, args)
		var pipelineName = args[0]

		var runParameters map[string]any
		if len(args) < 2 {
			runParameters = make(map[string]any)
		} else {

			err := json.Unmarshal([]byte(args[1]), &runParameters)
			if err != nil {
				log.Fatalf("Unable to marshal JSON due to %s", err)
			}
		}

		clientFactory, err := GetClientFactory(subscriptionId)
		if err != nil {
			log.Fatalf("failed to create client: %v", err)
		}

		ctx := context.Background()
		log.Println("running pipeline...")
		res, err := clientFactory.NewPipelinesClient().CreateRun(ctx, resourceGroupName, factoryName, pipelineName, &armdatafactory.PipelinesClientCreateRunOptions{ReferencePipelineRunID: nil,
			IsRecovery:        nil,
			StartActivityName: nil,
			StartFromFailure:  nil,
			Parameters:        runParameters,
		})
		if err != nil {
			log.Fatalf("failed to finish the request: %v", err)
		} else {
			log.Printf("success! Run ID: %v\n", *res.RunID)
		}
	},
}

getCmd represents the get command

Functions

func GetArgs

func GetArgs(cmd *cobra.Command, args []string) (string, string, string)

Get the subscriptionId, resourceGroupName, and factoryName from the environment variables or command line flags. If the values are not set, the program will exit.

func GetClientFactory

func GetClientFactory(subscriptionId string) (*armdatafactory.ClientFactory, error)

Create a new client factory with the default Azure credential If the credential cannot be obtained, the program will exit.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL