-
Notifications
You must be signed in to change notification settings - Fork 268
Description
Consider the next azd project sample:
name: ehooks
hooks:
preprovision:
shell: sh
continueOnError: false
interactive: true
run: echo "Preprovisioning..."If we run azd provision --no-prompt and:
- there's is not an
.azurefolder: The hook is not triggered b/c there is no environment.
hooks.go:52: azd environment is not available, skipping all hook registrations
See: Azure-Samples/azure-search-openai-demo#1603
This is an issue when azd runs in CI, because the .azure folder is not in the repo. Instead, azd uses AZURE_ENV_NAME to create the .azure folder with a new env using the name from that env var.
However, the hooks registration happens before the environment is created, so the hooks are ignored.
Workaround:
For CI, add one step to create the environment before calling azd provision, like:
- name: Create azd env
run: azd env new $AZURE_ENV_NAME
env:
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}The --no-prompt flag is not supported for azd env new, so, we need to use the env var from github as the argument for creating the environment.
Reproduce locally
- Create a simple azd project, (for example, use
azd initwith minimal template) - Add a
preprovisionhook like the one mentioned above - delete folder
.azure(leaving the state as it would be in CI) - set env var AZURE_ENV_VAR to something
- run
azd provision --no-promptand observe how hook is ignored and the .azure folder is created. If you run it again, the hook is now honored (b/c the env is there)
nzthiago and MadhuraBharadwaj-MSFT