Skip to content
Merged
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
1 change: 1 addition & 0 deletions .nextchanges/bundles/workspace-template-variable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Expose the workspace of the selected profile to bundle templates as `.workspace`, with `Hostname`, `ID`, and `URL`, so templates can address a workspace on a host shared by several workspaces. A template input named `workspace` takes precedence. ([#7349](https://github.com/databricks/cli/pull/7349))
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"properties": {
"workspace": {
"type": "boolean",
"description": "Create a workspace",
"default": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace: {{ .workspace }}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"workspace": ""}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"workspace": false}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"workspace": "Team Dev"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"workspace": "team-dev"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"workspace": 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"properties": {
"workspace": {
"type": "integer",
"description": "Workspace number",
"default": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace: {{ .workspace }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"welcome_message": "Welcome, {{ .workspace }}",
"properties": {
"workspace": {
"type": "string",
"description": "Workspace name",
"default": "team-prod"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace: {{ .workspace }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DMS = ["", "true"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@

=== String input

>>> [CLI] bundle debug render-template-schema ./string
{
"welcome_message": null,
"success_message": "Created for \"\"",
"properties": {
"message": {
"description": "Message for ",
"default": "Deploying to "
},
"workspace": {
"description": "Workspace name",
"default": ""
}
}
}

>>> [CLI] bundle debug render-template-schema ./string --input-file input.value.json
{
"welcome_message": null,
"success_message": "Created for \"team-dev\"",
"properties": {
"message": {
"description": "Message for team-dev",
"default": "Deploying to team-dev"
},
"workspace": {
"description": "Workspace name",
"default": ""
}
}
}

>>> [CLI] bundle init ./string
Created for ""
workspace_name: ""
message: "Deploying to "

>>> [CLI] bundle init ./string --config-file input.empty.json
Created for ""
workspace_name: ""
message: "Deploying to "

>>> [CLI] bundle init ./string --config-file input.value.json
Created for "team-dev"
workspace_name: "team-dev"
message: "Deploying to team-dev"

>>> musterr [CLI] bundle init ./string --config-file input.invalid.json
Error: failed to load config from file input.invalid.json: invalid value for workspace: "Team Dev". Use lowercase letters and dashes

=== Input without a value yet

>>> [CLI] bundle debug render-template-schema ./no_value
{
"welcome_message": "Welcome, team-prod",
"success_message": null,
"properties": {
"workspace": {
"description": "Workspace name",
"default": "team-prod"
}
}
}

>>> musterr [CLI] bundle init ./no_value
Error: variable "workspace" not defined

>>> [CLI] bundle init ./no_value --config-file input.value.json
Welcome, team-dev
✨ Successfully initialized template
workspace: team-dev

=== Boolean input

>>> [CLI] bundle init ./boolean
✨ Successfully initialized template
workspace: false

>>> [CLI] bundle init ./boolean --config-file input.false.json
✨ Successfully initialized template
workspace: false

=== Integer input

>>> [CLI] bundle init ./integer
✨ Successfully initialized template
workspace: 0

>>> [CLI] bundle init ./integer --config-file input.zero.json
✨ Successfully initialized template
workspace: 0

=== Undeclared input

>>> [CLI] bundle debug render-template-schema ./undeclared --input-file input.value.json
{
"welcome_message": "workspace: {[CUSTOM_HOSTNAME] [CUSTOM_HOST] [WORKSPACE_ID] [WORKSPACE_ID]}",
"success_message": null,
"properties": {}
}

>>> [CLI] bundle init ./undeclared --config-file input.value.json
workspace: {[CUSTOM_HOSTNAME] [CUSTOM_HOST] [WORKSPACE_ID] [WORKSPACE_ID]}
✨ Successfully initialized template
workspace: {[CUSTOM_HOSTNAME] [CUSTOM_HOST] [WORKSPACE_ID] [WORKSPACE_ID]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# A template input named "workspace" takes precedence over the workspace
# context, with and without a value supplied.
export DATABRICKS_CONFIG_PROFILE=workspace_custom_host

title "String input\n"
trace $CLI bundle debug render-template-schema ./string | schema_fields
trace $CLI bundle debug render-template-schema ./string --input-file input.value.json | schema_fields
for config in "" "--config-file input.empty.json" "--config-file input.value.json"; do
trace $CLI bundle init ./string $config
cat workspace.txt
rm workspace.txt
done
trace musterr $CLI bundle init ./string --config-file input.invalid.json

# The welcome message is rendered before inputs get their values. The input
# still owns the name, so the workspace context isn't used in its place.
title "Input without a value yet\n"
trace $CLI bundle debug render-template-schema ./no_value | schema_fields
trace musterr $CLI bundle init ./no_value
trace $CLI bundle init ./no_value --config-file input.value.json
cat workspace.txt
rm workspace.txt

title "Boolean input\n"
for config in "" "--config-file input.false.json"; do
trace $CLI bundle init ./boolean $config
cat workspace.txt
rm workspace.txt
done

title "Integer input\n"
for config in "" "--config-file input.zero.json"; do
trace $CLI bundle init ./integer $config
cat workspace.txt
rm workspace.txt
done

# An input value that the schema doesn't declare doesn't claim the name, so
# schema rendering and bundle init both use the workspace context.
title "Undeclared input\n"
trace $CLI bundle debug render-template-schema ./undeclared --input-file input.value.json | schema_fields
trace $CLI bundle init ./undeclared --config-file input.value.json
cat workspace.txt
rm workspace.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"properties": {
"workspace": {
"type": "string",
"description": "Workspace name",
"default": "",
"pattern": "^[a-z-]*$",
"pattern_match_failure_message": "Use lowercase letters and dashes",
"order": 1
},
"message": {
"type": "string",
"description": "Message for {{ .workspace }}",
"default": "Deploying to {{ .workspace }}",
"order": 2
}
},
"success_message": "Created for \"{{ .workspace }}\""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
workspace_name: "{{ .workspace }}"
message: "{{ .message }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"welcome_message": "workspace: {{ .workspace }}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace: {{ .workspace }}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ID: {{ .workspace.ID }}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"path": "https://other.test/jobs"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"path": "/pipelines?tab=all", "jobs_url": "https://example.test/my-jobs"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"path": "/jobs?w=999;x=1"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"path": "/jobs?o=123"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DMS = ["", "true"]
Loading
Loading