Azure / Azure/azure-dev

Hooks cannot be conditionally skipped, so operators cannot vary lifecycle behavior per invocation

Open
#9,320 0 comments 0 reactions 0 assignees View on GitHub
area/hooks enhancement
Dominant language
Go
Stars
569
Forks
364
Avg merge
2d 19h
Merged PRs (30d)
136

Description

### Problem

`HookConfig` in `cli/azd/pkg/ext/models.go` exposes `continueOnError`, `interactive`, `kind`, `shell`, `dir`, `run`, `secrets`, and `config`. It has no `condition`, `when`, `enabled`, or equivalent field. There is no `--skip-hooks` flag and no `AZD_SKIP_HOOKS` environment variable anywhere in the codebase.

A configured hook runs on every invocation of its lifecycle event. The only control available is whether a failure stops the command.

### Impact

Real deployments need the same project to behave differently across invocations. Common cases include running an expensive or destructive lifecycle step only when something relevant changed, skipping a data-affecting step for a code-only rollout, and disabling a step during recovery.

With no first-class mechanism, every consumer implements the same workaround: an early-exit environment variable check written by hand inside each script. That workaround has concrete deficiencies:

- The contract is invisible to `azd`. Nothing validates it, and no error is raised when a caller sets a flag no hook honors.
- It must be reimplemented, consistently, in every script and in every shell variant a project supports. A missed early return in one variant silently executes the step the operator intended to skip.
- It cannot be asserted from outside. An operator has no way to confirm from the command line or from output that a given hook did not run.
- The failure mode is silent execution of the thing that was supposed to be skipped, which for a data-affecting step is not recoverable by retry.

### Proposed requirement

1. Add a `condition` field to hook configuration, evaluated against environment values, so a hook can declare when it applies.
2. Add `--skip-hooks` to skip all hooks, and `--skip-hook ` to skip specific hooks, on the commands that run them.
3. Report skipped hooks in command output, naming the hook and the reason, so the skip is observable rather than inferred.

### Acceptance criteria

- [ ] Hook config accepts a `condition` expression evaluated against environment values
- [ ] `--skip-hooks` and `--skip-hook ` are available on hook-running commands
- [ ] Skipped hooks are named in output along with why they were skipped
- [ ] Skipping is covered by tests, including that a skipped hook produces no side effects
- [ ] `azure.yaml` schema and hook documentation updated

Contributor guide

Open the contributing guide

Research direction

Start in cli/azd/pkg/ext/models.go to trace HookConfig and then locate the commands that run lifecycle hooks. Review the azure.yaml schema and hook documentation alongside existing hook tests or command output paths. Done means conditional and explicit hook skipping, observable skip reasons, side-effect coverage, and updated schema and documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.