diff --git a/acceptance/pipelines/deploy/fail-on-active-runs/databricks.yml b/acceptance/pipelines/deploy/fail-on-active-runs/databricks.yml new file mode 100644 index 0000000000..854a1d112f --- /dev/null +++ b/acceptance/pipelines/deploy/fail-on-active-runs/databricks.yml @@ -0,0 +1,6 @@ +bundle: + name: pipeline-fail-on-active-runs +resources: + pipelines: + my_pipeline: + name: pipeline-fail-on-active-runs diff --git a/acceptance/pipelines/deploy/fail-on-active-runs/out.test.toml b/acceptance/pipelines/deploy/fail-on-active-runs/out.test.toml new file mode 100644 index 0000000000..387f29e8bb --- /dev/null +++ b/acceptance/pipelines/deploy/fail-on-active-runs/out.test.toml @@ -0,0 +1,5 @@ +Local = true +Cloud = false + +[EnvMatrix] + DATABRICKS_CLI_DEPLOYMENT = ["terraform"] diff --git a/acceptance/pipelines/deploy/fail-on-active-runs/output.txt b/acceptance/pipelines/deploy/fail-on-active-runs/output.txt new file mode 100644 index 0000000000..800306447c --- /dev/null +++ b/acceptance/pipelines/deploy/fail-on-active-runs/output.txt @@ -0,0 +1,12 @@ + +>>> [PIPELINES] deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/pipeline-fail-on-active-runs/default/files... +Deploying resources... +Updating deployment state... +Deployment complete! + +>>> errcode [PIPELINES] deploy --fail-on-active-runs +Error: pipeline [UUID] is running + + +Exit code: 1 diff --git a/acceptance/pipelines/deploy/fail-on-active-runs/script b/acceptance/pipelines/deploy/fail-on-active-runs/script new file mode 100644 index 0000000000..3894cb7d7a --- /dev/null +++ b/acceptance/pipelines/deploy/fail-on-active-runs/script @@ -0,0 +1,4 @@ +trace $PIPELINES deploy + +# We deploy the bundle again to check that the deploy is failing if the job is running +trace errcode $PIPELINES deploy --fail-on-active-runs diff --git a/acceptance/pipelines/deploy/fail-on-active-runs/test.toml b/acceptance/pipelines/deploy/fail-on-active-runs/test.toml new file mode 100644 index 0000000000..bf36891b04 --- /dev/null +++ b/acceptance/pipelines/deploy/fail-on-active-runs/test.toml @@ -0,0 +1,14 @@ +# Deploy relies on terraform.CheckRunningResource() +EnvMatrix.DATABRICKS_CLI_DEPLOYMENT = ["terraform"] + +# Cycling between states not implemented yet +# spec to avoid "pipeline spec is nil" error + +[[Server]] +Pattern = "GET /api/2.0/pipelines/{pipeline_id}" +Response.Body = ''' +{ + "state": "RUNNING", + "spec": {} +} +''' diff --git a/cmd/bundle/deploy.go b/cmd/bundle/deploy.go index 8ce265927c..a65f8a3e86 100644 --- a/cmd/bundle/deploy.go +++ b/cmd/bundle/deploy.go @@ -1,3 +1,5 @@ +// Copied to cmd/pipelines/deploy.go and adapted for pipelines use. +// Consider if changes made here should be made to the pipelines counterpart as well. package bundle import ( diff --git a/cmd/pipelines/deploy.go b/cmd/pipelines/deploy.go index 0ebdf04bae..f508fa8fc6 100644 --- a/cmd/pipelines/deploy.go +++ b/cmd/pipelines/deploy.go @@ -1,4 +1,5 @@ // Copied from cmd/bundle/deploy.go and adapted for pipelines use. +// Consider if changes made here should be made to the bundle counterpart as well. package pipelines import ( @@ -22,9 +23,11 @@ func deployCommand() *cobra.Command { } var forceLock bool + var failOnActiveRuns bool var autoApprove bool var verbose bool cmd.Flags().BoolVar(&forceLock, "force-lock", false, "Force acquisition of deployment lock.") + cmd.Flags().BoolVar(&failOnActiveRuns, "fail-on-active-runs", false, "Fail if there are running pipelines in the deployment.") cmd.Flags().BoolVar(&autoApprove, "auto-approve", false, "Skip interactive approvals that might be required for deployment.") cmd.Flags().BoolVar(&verbose, "verbose", false, "Enable verbose output.") // Verbose flag currently only affects file sync output, it's used by the vscode extension @@ -33,15 +36,19 @@ func deployCommand() *cobra.Command { cmd.RunE = func(cmd *cobra.Command, args []string) error { ctx := logdiag.InitContext(cmd.Context()) cmd.SetContext(ctx) - b := utils.ConfigureBundleWithVariables(cmd) - if logdiag.HasError(ctx) { + b := utils.ConfigureBundleWithVariables(cmd) + if b == nil || logdiag.HasError(ctx) { return root.ErrAlreadyPrinted } bundle.ApplyFuncContext(ctx, b, func(context.Context, *bundle.Bundle) { b.Config.Bundle.Deployment.Lock.Force = forceLock b.AutoApprove = autoApprove + + if cmd.Flag("fail-on-active-runs").Changed { + b.Config.Bundle.Deployment.FailOnActiveRuns = failOnActiveRuns + } }) var outputHandler sync.OutputHandler