Skip to content

Commit 9ec55d5

Browse files
authored
pipelines: update deploy.go and add fail-on-active-runs flag (#3235)
## Changes Synchronize deploy.go to cmd/bundle/deploy.go and add new `fail-on-active-runs` flag ## Why New flag is for controlling that pipelines deploy fails when the pipeline is currently running ## Tests Added pipeline specific test that causes deploy to fail when pipeline is running and `fail-on-active-runs` is set
1 parent afc345f commit 9ec55d5

File tree

7 files changed

+52
-2
lines changed

7 files changed

+52
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bundle:
2+
name: pipeline-fail-on-active-runs
3+
resources:
4+
pipelines:
5+
my_pipeline:
6+
name: pipeline-fail-on-active-runs
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Local = true
2+
Cloud = false
3+
4+
[EnvMatrix]
5+
DATABRICKS_CLI_DEPLOYMENT = ["terraform"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
>>> [PIPELINES] deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/pipeline-fail-on-active-runs/default/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
7+
8+
>>> errcode [PIPELINES] deploy --fail-on-active-runs
9+
Error: pipeline [UUID] is running
10+
11+
12+
Exit code: 1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
trace $PIPELINES deploy
2+
3+
# We deploy the bundle again to check that the deploy is failing if the job is running
4+
trace errcode $PIPELINES deploy --fail-on-active-runs
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Deploy relies on terraform.CheckRunningResource()
2+
EnvMatrix.DATABRICKS_CLI_DEPLOYMENT = ["terraform"]
3+
4+
# Cycling between states not implemented yet
5+
# spec to avoid "pipeline spec is nil" error
6+
7+
[[Server]]
8+
Pattern = "GET /api/2.0/pipelines/{pipeline_id}"
9+
Response.Body = '''
10+
{
11+
"state": "RUNNING",
12+
"spec": {}
13+
}
14+
'''

cmd/bundle/deploy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copied to cmd/pipelines/deploy.go and adapted for pipelines use.
2+
// Consider if changes made here should be made to the pipelines counterpart as well.
13
package bundle
24

35
import (

cmd/pipelines/deploy.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copied from cmd/bundle/deploy.go and adapted for pipelines use.
2+
// Consider if changes made here should be made to the bundle counterpart as well.
23
package pipelines
34

45
import (
@@ -22,9 +23,11 @@ func deployCommand() *cobra.Command {
2223
}
2324

2425
var forceLock bool
26+
var failOnActiveRuns bool
2527
var autoApprove bool
2628
var verbose bool
2729
cmd.Flags().BoolVar(&forceLock, "force-lock", false, "Force acquisition of deployment lock.")
30+
cmd.Flags().BoolVar(&failOnActiveRuns, "fail-on-active-runs", false, "Fail if there are running pipelines in the deployment.")
2831
cmd.Flags().BoolVar(&autoApprove, "auto-approve", false, "Skip interactive approvals that might be required for deployment.")
2932
cmd.Flags().BoolVar(&verbose, "verbose", false, "Enable verbose output.")
3033
// Verbose flag currently only affects file sync output, it's used by the vscode extension
@@ -33,15 +36,19 @@ func deployCommand() *cobra.Command {
3336
cmd.RunE = func(cmd *cobra.Command, args []string) error {
3437
ctx := logdiag.InitContext(cmd.Context())
3538
cmd.SetContext(ctx)
36-
b := utils.ConfigureBundleWithVariables(cmd)
3739

38-
if logdiag.HasError(ctx) {
40+
b := utils.ConfigureBundleWithVariables(cmd)
41+
if b == nil || logdiag.HasError(ctx) {
3942
return root.ErrAlreadyPrinted
4043
}
4144

4245
bundle.ApplyFuncContext(ctx, b, func(context.Context, *bundle.Bundle) {
4346
b.Config.Bundle.Deployment.Lock.Force = forceLock
4447
b.AutoApprove = autoApprove
48+
49+
if cmd.Flag("fail-on-active-runs").Changed {
50+
b.Config.Bundle.Deployment.FailOnActiveRuns = failOnActiveRuns
51+
}
4552
})
4653

4754
var outputHandler sync.OutputHandler

0 commit comments

Comments
 (0)