Azure Lifecycle Scripts
Lifecycle scripts are Python files strata runs before or after deploy stages. The
AzureScript base class gives scripts pre-wired access to the Azure CLI — no setup
required.
Quick start — use a built-in script
Reference built-in scripts directly from workspace YAML lifecycle hooks:
lifecycle:
pre_deploy:
scripts:
# Fetch AKS credentials so Helm / ArgoCD can reach the cluster
- strata://azure_aks_credentials.py
# Log Docker into Azure Container Registry before image push
- strata://azure_acr_login.py
pre_provision:
scripts:
# Ensure resource group exists before Bicep subscription-scope deploy
- strata://azure_resource_group_ensure.py
Tip:
strata://references resolve to strata’s built-in scripts directory at runtime. Copy any script to.strata/scripts/and modify it as needed.
Built-in scripts
azure_aks_credentials.py
Runs az aks get-credentials --overwrite-existing to merge cluster credentials
into the local kubeconfig. Use before Helm, ArgoCD, or Flux stages targeting AKS.
Required variables:
Variable |
Description |
|---|---|
|
AKS cluster name |
|
Resource group containing the cluster |
Optional variables:
Variable |
Default |
Description |
|---|---|---|
|
active subscription |
Subscription ID override |
|
|
Set to |
|
— |
Override kubeconfig context name |
variables:
- key: AKS_CLUSTER
source: constant
value: my-aks-cluster
- key: AKS_RESOURCE_GROUP
source: constant
value: my-resource-group
azure_acr_login.py
Runs az acr login --name <registry> so Docker push/pull commands work against
Azure Container Registry in the same stage.
Required variables:
Variable |
Description |
|---|---|
|
Registry name (without |
Optional:
Variable |
Description |
|---|---|
|
Subscription ID override |
|
Set to |
variables:
- key: ACR_NAME
source: constant
value: myregistry
azure_resource_group_ensure.py
Runs az group create — idempotent: if the resource group already exists the
command succeeds and makes no changes. Use before subscription-scope Bicep deploys.
Required variables:
Variable |
Description |
|---|---|
|
Resource group name |
|
Azure region (e.g. |
Optional:
Variable |
Description |
|---|---|
|
Subscription ID override |
|
Comma-separated |
variables:
- key: AZURE_RESOURCE_GROUP
source: constant
value: my-rg-prod
- key: AZURE_LOCATION
source: constant
value: westeurope
Write a custom script
Subclass AzureScript in .strata/scripts/:
# .strata/scripts/pre_deploy_custom.py
from strata.utils.azure_script_base import AzureScript
class MyPreDeploy(AzureScript):
def run(self):
rg = self.require_env("AZURE_RESOURCE_GROUP") # exits with error if absent
subscription = self.env("AZURE_SUBSCRIPTION") # empty string if absent
# Run any az command
args = ["group", "show", "--name", rg, "--output", "json"]
if subscription:
args += ["--subscription", subscription]
result = self.run_az(args)
self.exit_on_failure(result, "az group show") # sys.exit(1) on failure
self.log(f"Resource group '{rg}' confirmed") # printed to strata output
if __name__ == "__main__":
MyPreDeploy().execute()
Reference it in workspace YAML:
lifecycle:
pre_deploy:
scripts:
- .strata/scripts/pre_deploy_custom.py
AzureScript reference
Method |
Description |
|---|---|
|
Run |
|
|
|
Return env var value or |
|
Return env var value with optional default |
|
Cached bearer token via |
|
|
|
|
|
Stage name from |
|
Print to stderr — visible in strata console output |
Environment variables in all lifecycle scripts
strata injects these before running any script:
Variable |
Content |
|---|---|
|
Current lifecycle phase (e.g. |
|
Workspace root path |
|
Build artifacts directory |
|
|
|
Current stage name |
all resolved variables |
Secrets and variables from the active deployment |