Skip to content

Project hooks don't work when there's not environment, like in CI/CD #3920

@vhvb1989

Description

@vhvb1989

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 .azure folder: 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 init with minimal template)
  • Add a preprovision hook 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-prompt and 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)

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions