Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion acceptance/bundle/help/bundle-validate/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Validate bundle configuration for errors, warnings and recommendations.
Run validate before deploy to catch configuration issues early:
databricks bundle validate # Validate default target
databricks bundle validate --target prod # Validate specific target
databricks bundle validate --strict # Fail on warnings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a global option? So that you can specify it on plan, deploy, summary etc.

Copy link
Contributor Author

@shreyas-goenka shreyas-goenka Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe? In general adding warnings is not a breaking change. As a user, using this option would mean breaking changes during deployment which is not great.

We definitely should not add it to summary / open etc. Those should not fail if we detect some warning.


Validation checks the configuration syntax and schema, permissions etc.

Expand All @@ -14,7 +15,8 @@ Usage:
databricks bundle validate [flags]

Flags:
-h, --help help for validate
-h, --help help for validate
--strict Treat warnings as errors

Global Flags:
--debug enable debug logging
Expand Down
17 changes: 17 additions & 0 deletions acceptance/bundle/validate/strict/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
bundle:
name: test-bundle

variables:
my_variable:
type: INVALID_TYPE
default: "value"

targets:
foo:
default: true

bar:
artifacts:
my_artifact:
type: INVALID_TYPE
build: "echo 'hello'"
5 changes: 5 additions & 0 deletions acceptance/bundle/validate/strict/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions acceptance/bundle/validate/strict/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

>>> [CLI] bundle validate
Warning: invalid value "INVALID_TYPE" for enum field. Valid values are [complex]
at variables.my_variable.type
in databricks.yml:6:11

Name: test-bundle
Target: foo
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/foo

Found 1 warning

>>> [CLI] bundle validate --strict
Warning: invalid value "INVALID_TYPE" for enum field. Valid values are [complex]
at variables.my_variable.type
in databricks.yml:6:11

Name: test-bundle
Target: foo
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/foo

Found 1 warning
Error: 1 warning was found. Warnings are not allowed in strict mode

Exit code: 1

>>> [CLI] bundle validate --strict -t bar
Warning: invalid value "INVALID_TYPE" for enum field. Valid values are [complex]
at variables.my_variable.type
in databricks.yml:6:11

Warning: invalid value "INVALID_TYPE" for enum field. Valid values are [whl jar]
at artifacts.my_artifact.type
in databricks.yml:16:15

Name: test-bundle
Target: bar
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/bar

Found 2 warnings
Error: 2 warnings were found. Warnings are not allowed in strict mode

Exit code: 1
7 changes: 7 additions & 0 deletions acceptance/bundle/validate/strict/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Without --strict, warnings don't cause exit code 1
trace $CLI bundle validate

# With --strict, warnings cause exit code 1
errcode trace $CLI bundle validate --strict

errcode trace $CLI bundle validate --strict -t bar
16 changes: 16 additions & 0 deletions cmd/bundle/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bundle

import (
"encoding/json"
"fmt"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/render"
Expand Down Expand Up @@ -35,6 +36,7 @@ func newValidateCommand() *cobra.Command {
Run validate before deploy to catch configuration issues early:
databricks bundle validate # Validate default target
databricks bundle validate --target prod # Validate specific target
databricks bundle validate --strict # Fail on warnings

Validation checks the configuration syntax and schema, permissions etc.

Expand All @@ -43,8 +45,10 @@ Please run this command before deploying to ensure configuration quality.`,
}

var includeLocations bool
var strict bool
cmd.Flags().BoolVar(&includeLocations, "include-locations", false, "Include location information in the output")
cmd.Flags().MarkHidden("include-locations")
cmd.Flags().BoolVar(&strict, "strict", false, "Treat warnings as errors")

cmd.RunE = func(cmd *cobra.Command, args []string) error {
b, err := utils.ProcessBundle(cmd, utils.ProcessOptions{
Expand Down Expand Up @@ -74,6 +78,18 @@ Please run this command before deploying to ensure configuration quality.`,
}
}

// In strict mode, treat warnings as errors.
numWarnings := logdiag.NumWarnings(ctx)
if err == nil && strict && numWarnings > 0 {
prefix := ""
if numWarnings == 1 {
prefix = "1 warning was found"
} else {
prefix = fmt.Sprintf("%d warnings were found", numWarnings)
}
return fmt.Errorf("%s. Warnings are not allowed in strict mode", prefix)
}

return err
}

Expand Down
8 changes: 8 additions & 0 deletions libs/logdiag/logdiag.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ func HasError(ctx context.Context) bool {
return val.Errors > 0
}

func NumWarnings(ctx context.Context) int {
val := read(ctx)
val.mu.Lock()
defer val.mu.Unlock()

return val.Warnings
}

func SetSeverity(ctx context.Context, target diag.Severity) {
val := read(ctx)
val.mu.Lock()
Expand Down