Skip to content

Add hidden bundle deployment auto-deploy group with create - #8185

Open
atreyadbrx wants to merge 1 commit into
mainfrom
dabs-ad-d4-dep-pr3-create
Open

atreyadbrx wants to merge 1 commit into
mainfrom
dabs-ad-d4-dep-pr3-create

Conversation

@atreyadbrx

@atreyadbrx atreyadbrx commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

This is #7940 with the group under bundle deployment, as suggested in review: users run it once, at setup time, so the extra level of nesting is fine. Only the command path, the package path (cmd/bundle/deployment/autodeploy) and the test paths differ.

Changes

  • Adds a bundle deployment auto-deploy command group, hidden for now, with create. create sets up the trigger that deploys a bundle target on every push to a branch. It is identified by bundle.git.origin_url, the bundle's path in the repo (bundle.git.bundle_root_path plus the config file name), and the target.
  • --git-provider is needed only for hosts other than github.com and dev.azure.com. It takes the same case-insensitive values as apps and repos (gitHub, gitLab, ...). --branch defaults to bundle.git.branch, or to the current branch when git.branch resolves to "". --deploy-as takes a service principal application ID or your own email, which is all the service accepts. It defaults to you.
  • create fails early in three cases, each with a fix in the error message:
    • --branch differs from the target's configured git.branch, since that deploy would fail the branch check.
    • The origin isn't an HTTPS URL. The service keys and clones webhooks over HTTPS.
    • A variable is set locally, through --var, BUNDLE_VAR_<name> or the target's variable-overrides file (only an entry that sets a defined, non-lookup variable counts). The runner deploys from a clone that has none of them. This makes VariableEnvPrefix and VariableOverridesPath in bundle/config/mutator exported.
  • The commands load the bundle's Git details and variables (with a new ResolveVariableReferencesInGit for bundle.git), not the full Initialize. Its target-mode checks, run_as checks and lookups run as the caller, but the deploys run as --deploy-as.
  • New libs/gitwebhooks: a client for the git-webhooks API (PUT /api/2.0/git-webhooks). The fake handlers are in libs/testserver/gitwebhooks.go.

Why

Auto-deploy needs a CLI way to set up a trigger for a bundle target. The git-webhooks API isn't in the public spec or the Go SDK yet, so libs/gitwebhooks calls it through client.Do with local types that mirror the service, like libs/dms/enrollments.go does. The group stays hidden until the API is public.

Tests

  • acceptance/bundle/deployment/auto-deploy/create covers:
    • defaults, and an update of an existing trigger (same trigger ID)
    • --deploy-as with a service principal, with your own email (-o json) and with another user's email (rejected)
    • a mode: production target without root_path, with --deploy-as a service principal
    • a lookup variable, which create does not resolve, also set in the overrides file
    • a --branch that conflicts with git.branch, a git.branch set from a variable, one that resolves to "", and a detached HEAD
    • a bundle in a subdirectory of the repository
    • an unknown host with and without --git-provider, and an unsupported --git-provider
    • an SSH origin, --var, BUNDLE_VAR_<name>, an overrides file that sets a defined variable and one that doesn't, and a repo with no origin
  • Unit tests for provider inference and --git-provider parsing.
  • Only the fake server checks create's request: the enum strings, deployment_mode carrying the target, the response fields, and the 403 for another user's email. The fake follows the service's implemented behavior. A staging workspace that serves the API returned triggers in the shape these types expect (see Add bundle deployment auto-deploy get and list #8186), but create was not run there.

This pull request and its description were written by Isaac.

@atreyadbrx
atreyadbrx requested review from a team as code owners November 30, 2026 08:38
@atreyadbrx
atreyadbrx requested review from denik and pietern November 30, 2026 08:38
@github-actions github-actions Bot added the DABs DABs related issues label Nov 30, 2026

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated review at 31284b0. Each finding was verified against the code.

No blocking issues found. 4 non-blocking comment(s) below.

This PR adds a hidden bundle deployment auto-deploy create command that upserts a git-webhooks trigger for a bundle target, along with a small libs/gitwebhooks client and a fake server handler. The main flow and the branch, origin and override checks look right. I'd like three things fixed before this becomes public. Provider inference duplicates repos.DetectProvider and covers fewer hosts. The variable-overrides check rejects file entries for lookup variables, even though the deploy ignores them. A production target can fail validation under the caller's identity even when --deploy-as names a service principal that the same target accepts. There is also one small test-input rule violation.


// Auto-deploy infers only these providers. Any other host takes --git-provider, since
// a host name does not tell, for example, GitHub Enterprise from GitLab self-managed.
var providersByHost = map[string]gitwebhooks.GitProvider{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nice to have] repos.DetectProvider in cmd/workspace/repos/provider.go already infers the provider from the origin URL. It covers github.com and dev.azure.com, and also gitlab.com, bitbucket.org and git-codecommit.<region>.amazonaws.com. Its result uses the same names that gitProviderNames maps. With this map, an origin of https://gitlab.com/acme/repo fails with "cannot infer the Git provider ... Pass it with --git-provider", but databricks repos create detects the same URL. These public hosts aren't ambiguous the way a self-managed host is. Can we call repos.DetectProvider and feed its result through parseGitProvider? The --git-provider help text and the Long text in create.go would then need updating to match.

return ""
}
for name := range b.Config.Variables {
if value, ok := values[name]; ok && string(value) != "null" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nice to have] The comment says this works "Like SetVariables", but setVariable returns at variable.Lookup != nil before it reads the file value. So the overrides file never sets a lookup variable. Take a bundle with cluster_id: {lookup: {cluster: ...}} and {"cluster_id": "abc"} in .databricks/bundle/<target>/variable-overrides.json: create refuses, even though the local deploy and the runner's deploy both ignore that entry. Can this loop skip variables whose Lookup is set? Only skip them for the file check, since BUNDLE_VAR_<name> does take priority over a lookup. Another option is to check what SetVariables actually applied instead of parsing the file a second time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Should fix: +1, reproduced with a scratch acceptance test. With policy_id: {lookup: {cluster_policy: shared}} and {"policy_id": "old"} in .databricks/bundle/dev/variable-overrides.json, bundle validate still resolves policy_id to the lookup's ID, but create fails with ... variable-overrides.json overrides them here. This is the case left over from the overrides-file point raised on #7940. The fix there skips null values, but not lookup variables, which setVariable returns for before it reads the file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6568c9d. The overrides-file check now skips lookup variables, which SetVariables also skips. --var and BUNDLE_VAR_<name> still count, since they do override a lookup. The create test's overrides file now has an entry for a lookup variable (policy_id), and create succeeds. #7940 has the same fix.


// Whether the configuration sets the branch, before Initialize fills in the current one.
var branchConfigured bool
b, err := utils.ProcessBundle(cmd, utils.ProcessOptions{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nice to have] ProcessBundle runs the full phases.Initialize, which includes resourcemutator.ValidateTargetMode with the caller's identity. Suppose a human runs create -t prod --deploy-as <sp-id> on a mode: production target that has a job without run_as and no target-level workspace.root_path. The command fails with "target with 'mode: production' must set 'workspace.root_path'" before the upsert. The service principal's own deploys of that target only get a recommendation, because validateProductionMode makes this check non-fatal for principals. Should create skip caller-dependent validation, or run it as the --deploy-as identity?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Should fix: +1, reproduced with a scratch acceptance test (mode: production, a job without run_as, no root_path). create -t prod --deploy-as 692bc6d0-ffa3-11ed-be56-0242ac120002 fails with target with 'mode: production' must set 'workspace.root_path', and the suggested root_path has the caller's user name in it, not the principal's. Other checks that Initialize runs as the caller hit the same problem:

  • SetRunAs compares run_as with workspace.current_user, so run_as: {service_principal_name: <sp>} with a resource type that doesn't support a different run_as fails for the human, while the principal's own deploy passes.
  • Lookup variables resolve with the caller's access.

create sends only the origin, the bundle path, the target and the branch. So one way to fix all of these: resolve only what those need (Git details, the target, and the variables git.branch uses), instead of the full Initialize.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6568c9d, as you suggested. The commands now skip Initialize (SkipInitialize) and run only what they need:

  • the sync root
  • LoadGitDetails
  • SetVariables
  • a new ResolveVariableReferencesInGit, which resolves references under bundle.git only

So the target-mode checks, the run_as checks and lookups no longer run as the caller. get, list, delete and attempts load the bundle the same way (#8186).

The create test now has a mode: production target without root_path, with a job that has no run_as, and create -t prod --deploy-as <sp> succeeds. The test bundle also has a lookup variable, which create no longer resolves. #7940 and #7941 have the same fix.

musterr trace BUNDLE_VAR_release_branch=hotfix $CLI bundle deployment auto-deploy create -t staging
mkdir -p .databricks/bundle/staging
echo '{"undefined_variable": "x"}' > .databricks/bundle/staging/variable-overrides.json
trace $CLI bundle deployment auto-deploy create -t staging

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nit] .agents/rules/testing.md asks for static test inputs to be committed to the test directory instead of created in script. Both variable-overrides.json contents, here and on line 61, are fixed. Can we commit them next to the test (for example overrides-undefined.json and overrides-defined.json) and copy them into .databricks/bundle/staging/ when needed, like sub/databricks.yml?

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Regression test report ✅

Commit: 6568c9dbc | Workflow run

Selected 1 changed tests (limit=20, 0 not selected)

1 tests: regression=1 unreleased=0 coverage=0 failing=0
test branch main (9a14ad6) latest (v1.28.0)
TestAccept/bundle/deployment/auto-deploy/create ✅ ❌ ❌
TestAccept/bundle/deployment/auto-deploy/create: branch ✅ | main (9a14ad6) ❌ | latest (v1.28.0) ❌

main (9a14ad6):

acceptance_test.go:1402: Diff:
        --- bundle/deployment/auto-deploy/create/output.txt
        +++ /tmp/TestAcceptbundledeploymentauto-deploycreate194074076/002/output.txt
        @@ -2,289 +2,41 @@
         === The current branch, as the caller
         
         >>> [CLI] bundle deployment auto-deploy create
        -Pushes to branch main now deploy target dev as you.
        -Trigger ID: [UUID][0]
        -{
        -  "method": "PUT",
        -  "path": "/api/2.0/git-webhooks",
        -  "body": {
        -    "repo_url": "https://github.com/acme/repo",
        -    "git_provider": "GITHUB",
        -    "trigger_config": {
        -      "push_event": {
        -        "branch": "main"
        -      },
        -      "dabs_deploy": {
        -        "bundle_yml_repo_path": "databricks.yml",
        -        "deployment_mode": "dev"
        -      }
        -    }
        -  }
        -}
        +Deployment related commands for managing bundle resource bindings.
         
        -=== Updating the trigger keeps its ID
        +Use these commands to bind / unbind bundle definitions to existing workspace resources.
         
        ->>> [CLI] bundle deployment auto-deploy create --branch release --deploy-as [UUID][1]
        -Pushes to branch release now deploy target dev as [UUID][1].
        -Trigger ID: [UUID][0]
        -{
        -  "method": "PUT",
        -  "path": "/api/2.0/git-webhooks",
        -  "body": {
        -    "repo_url": "https://github.com/acme/repo",
        -    "git_provider": "GITHUB",
        -    "trigger_config": {
        -      "push_event": {
        -        "branch": "release"
        -      },
        -      "dabs_deploy": {
        -        "bundle_yml_repo_path": "databricks.yml",
        -        "deployment_mode": "dev",
        -        "deploy_as": {
        -          "service_principal_client_id": "[UUID][1]"
        -        }
        -      }
        -    }
        -  }
        -}
        +Common workflow:
        +1. Generate configuration from existing resource:
        +   databricks bundle generate job --existing-job-id 12345 --key my_job
         
        -=== As yourself, in JSON
        +2. Bind the bundle resource to the existing workspace resource:
        +   databricks bundle deployment bind my_job 12345
         
        ->>> [CLI] bundle deployment auto-deploy create -t prod --deploy-as [USERNAME] -o json
        -{
        -  "webhook_id": "[UUID][2]",
        -  "trigger_id": "[UUID][3]"
        -}
        -{
        -  "method": "PUT",
        -  "path": "/api/2.0/git-webhooks",
        -  "body": {
        -    "repo_url": "https://github.com/acme/repo",
        -    "git_provider": "GITHUB",
        -    "trigger_config": {
        -      "push_event": {
        -        "branch": "main"
        -      },
        -      "dabs_deploy": {
        -        "bundle_yml_repo_path": "databricks.yml",
        -        "deployment_mode": "prod",
        -        "deploy_as": {
        -          "user_email": "[USERNAME]"
        -        }
        -      }
        -    }
        -  }
        -}
        +3. Deploy updates - the bound resource will be updated in the workspace:
        +   databricks bundle deploy
         
        -=== As a service principal, on a production target that a user could not deploy
        +After binding, the existing workspace resource will be managed by your bundle.
         
        ->>> [CLI] bundle deployment auto-deploy create -t prod --deploy-as [UUID][1]
        -Pushes to branch main now deploy target prod as [UUID][1].
        -Trigger ID: [UUID][3]
        -{
        -  "method": "PUT",
        -  "path": "/api/2.0/git-webhooks",
        -  "body": {
        -    "repo_url": "https://github.com/acme/repo",
        -    "git_provider": "GITHUB",
        -    "trigger_config": {
        -      "push_event": {
        -        "branch": "main"
        -      },
        -      "dabs_deploy": {
        -        "bundle_yml_repo_path": "databricks.yml",
        -        "deployment_mode": "prod",
        -        "deploy_as": {
        -          "service_principal_client_id": "[UUID][1]"
        -        }
        -      }
        -    }
        -  }
        -}
        +Usage:
        +  databricks bundle deployment [command]
         
        -=== As another user
        +Available Commands:
        +  bind        Bind bundle-defined resources to existing resources
        +  migrate     Migrate from Terraform to Direct deployment engine
        +  unbind      Unbind bundle-defined resources from its managed remote resource
         
        ->>> musterr [CLI] bundle deployment auto-deploy create -t prod --deploy-as someone@example.com
        -Error: deploy_as.user_email must be your own email. To deploy as another identity, use a service principal you have the Service Principal User role on.
        +Flags:
        +  -h, --help[=true|false]   help for deployment
         
        -Host:      [DATABRICKS_URL]
        -Auth type: Personal Access Token (pat)
        +Global Flags:
        +      --debug[=true|false]   enable debug logging
        +  -o, --output type          output type: text or json (default text)
        +  -p, --profile string       ~/.databrickscfg profile
        +  -t, --target string        bundle target to use (if applicable)
        +      --var strings          set values for variables defined in bundle config. Example: --var="foo=bar"
         
        -Next steps:
        -  - Verify you have the required permissions for this operation
        -  - Check your identity: databricks auth describe
        -  - Consider setting up a profile: databricks auth login --profile <name>
        -{
        -  "method": "PUT",
        -  "path": "/api/2.0/git-webhooks",
        -  "body": {
        -    "repo_url": "https://github.com/acme/repo",
        -    "git_provider": "GITHUB",
        -    "trigger_config": {
        -      "push_event": {
        -        "branch": "main"
        -      },
        -      "dabs_deploy": {
        -        "bundle_yml_repo_path": "databricks.yml",
        -        "deployment_mode": "prod",
        -        "deploy_as": {
        -          "user_email": "someone@example.com"
        -        }
        -      }
        -    }
        -  }
        -}
        +Use "databricks bundle deployment [command] --help" for more information about a command.
        +File [OUTPUT_DIR]/out.requests.txt not found
         
        -=== A branch other than the target's git.branch
        -
        ->>> musterr [CLI] bundle deployment auto-deploy create -t prod --branch release
        -Error: git.branch is main for target prod, so a deploy from release would fail. Omit --branch, or change git.branch
        -
        -=== A git.branch from a variable
        -
        ->>> [CLI] bundle deployment auto-deploy create -t staging
        -Pushes to branch release now deploy target staging as you.
        -Trigger ID: [UUID][4]
        -{
        -  "method": "PUT",
        -  "path": "/api/2.0/git-webhooks",
        -  "body": {
        -    "repo_url": "https://github.com/acme/repo",
        -    "git_provider": "GITHUB",
        -    "trigger_config": {
        -      "push_event": {
        -        "branch": "release"
        -      },
        -      "dabs_deploy": {
        -        "bundle_yml_repo_path": "databricks.yml",
        -        "deployment_mode": "staging"
        -      }
        -    }
        -  }
        -}
        -
        -=== A git.branch that resolves to empty leaves the current branch
        -
        ->>> [CLI] bundle deployment auto-deploy create -t unpinned
        -Pushes to branch main now deploy target unpinned as you.
        -Trigger ID: [UUID][5]
        -
... (122 more lines truncated, raise DATABRICKS_CLI_TEST_MAX_LOG to see more)

latest (v1.28.0): same output as main (9a14ad6)

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: 6568c9d

Run: 46397326788

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 173 18 2:28
💚​ aws-windows-latest-4core-16gb 1 173 18 3:14
💚​ azure linux-2core-8gb 1 172 18 2:18
💚​ azure-windows-latest-4core-16gb 1 172 18 3:02
💚​ gcp linux-2core-8gb 1 173 18 2:31
💚​ gcp-windows-latest-4core-16gb 1 173 18 2:54
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 3 slowest tests (at least 2 minutes):
duration env testname
3:12 aws-windows-latest-4core-16gb TestAccept
3:00 azure-windows-latest-4core-16gb TestAccept
2:52 gcp-windows-latest-4core-16gb TestAccept

@denik denik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Automated review of 31284b0a3 by Opus and Astra (two independent passes); each finding verified against the code.

The move under bundle deployment is clean: the code is #7940's 30d20e72e with only the command path, the package path and the test paths changed. It builds and its tests pass when merged with current main. Of the three Should-fix points from the #7940 review, the empty git.branch lockout and the --git-provider spelling are fixed. The overrides-file check still has a lookup-variable case (reply inline). review-oss-bot's --deploy-as point also reproduces, and the same problem affects more checks than the one it names (reply inline).

return ""
}
for name := range b.Config.Variables {
if value, ok := values[name]; ok && string(value) != "null" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Should fix: +1, reproduced with a scratch acceptance test. With policy_id: {lookup: {cluster_policy: shared}} and {"policy_id": "old"} in .databricks/bundle/dev/variable-overrides.json, bundle validate still resolves policy_id to the lookup's ID, but create fails with ... variable-overrides.json overrides them here. This is the case left over from the overrides-file point raised on #7940. The fix there skips null values, but not lookup variables, which setVariable returns for before it reads the file.


// Whether the configuration sets the branch, before Initialize fills in the current one.
var branchConfigured bool
b, err := utils.ProcessBundle(cmd, utils.ProcessOptions{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Should fix: +1, reproduced with a scratch acceptance test (mode: production, a job without run_as, no root_path). create -t prod --deploy-as 692bc6d0-ffa3-11ed-be56-0242ac120002 fails with target with 'mode: production' must set 'workspace.root_path', and the suggested root_path has the caller's user name in it, not the principal's. Other checks that Initialize runs as the caller hit the same problem:

  • SetRunAs compares run_as with workspace.current_user, so run_as: {service_principal_name: <sp>} with a resource type that doesn't support a different run_as fails for the human, while the principal's own deploy passes.
  • Lookup variables resolve with the caller's access.

create sends only the origin, the bundle path, the target and the branch. So one way to fix all of these: resolve only what those need (Git details, the target, and the variables git.branch uses), instead of the full Initialize.

@denik
denik requested review from a team and denik November 30, 2026 09:33
`bundle deployment auto-deploy create` sets up the trigger that deploys a
bundle target on every push to a branch, over the git-webhooks API. The
trigger is identified by the bundle's origin URL, its path in the repository
and the target. The Git provider is inferred for github.com and dev.azure.com,
and --git-provider covers any other host. --branch defaults to
bundle.git.branch, and --deploy-as takes a user email or a service principal
application ID.

The group sits under `bundle deployment` rather than at the top of `bundle`:
users run it once, at setup time, so the extra level of nesting is fine.

The commands load the bundle's Git details and variables, not the rest of
Initialize. Its checks and lookups run as the caller, while the deploys run
as --deploy-as.

The git-webhooks API is not in the Go SDK yet, so libs/gitwebhooks calls it
with local types. The group stays hidden until the API is public.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: atreyadbrx <atreya.misra@databricks.com>
@atreyadbrx
atreyadbrx force-pushed the dabs-ad-d4-dep-pr3-create branch from 31284b0 to 6568c9d Compare November 30, 2026 10:07

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DABs DABs related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants