Skip to content

feat(atc): natively inject BUILD_STATUS into resource metadata - #9523

Merged
taylorsilva merged 4 commits into
concourse:masterfrom
arakakimarcelo:feat/build-state
Apr 14, 2026
Merged

taylorsilva merged 4 commits into
concourse:masterfrom
arakakimarcelo:feat/build-state

Conversation

@arakakimarcelo

Copy link
Copy Markdown
Contributor

When using a resource within a hook step (e.g., on_success, on_failure, on_error, on_abort), the execution step is now context-aware of the build state sequence that triggered it. This modifies the builder tree to propagate the hook's execution state down to the resource environment variable natively, reducing configuration redundancy.

Resolves #8541

Changes proposed by this PR

closes #8541

  • Modified atc/exec/step_metadata.go by adding a BuildState string that natively generates the BUILD_STATE environment variable.
  • Refactored step initialization throughout atc/engine/builder.go to thread a contextual tracking of the overarching BuildState.
  • Modified the specific on_success, on_failure, on_error, and on_abort builder wrappers to appropriately pass "succeeded", "failed", "errored", and "aborted" identifiers downstream when parsing nested plans.
  • Updated related atc/engine/builder_test.go and atc/exec/step_metadata_test.go test suites with explicit assertions checking that $BUILD_STATE parses correctly within nested pipeline hooks.

Notes to reviewer

The engine passes the state by mapping hook-specific constants directly (e.g., db.BuildStatusSucceeded) dynamically when establishing the hierarchical step tree layout inside .Next fields. This elegantly isolates the behavior down recursively regardless of how deep the in_parallel/do/try blocks scale.
All unit checks passed successfully validating this nested environment allocation.

Release Note

  • Added contextual $BUILD_STATE metadata generation globally natively exposed when instantiating arbitrary hooks (simplifying parameter configurations for notification resources out-of-the-box).

When using a resource within a hook step (e.g., on_success, on_failure, on_error, on_abort), the execution step is now context-aware of the build state sequence that triggered it. This modifies the builder tree to propagate the hook's execution state down to the resource environment variable  natively, reducing configuration redundancy.

Resolves concourse#8541
@arakakimarcelo
arakakimarcelo requested a review from a team April 12, 2026 14:10
@linux-foundation-easycla

linux-foundation-easycla Bot commented Apr 12, 2026 •

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

@arakakimarcelo

Copy link
Copy Markdown
Contributor Author

@taylorsilva can't seem to check what's wrong with validate-labels

@taylorsilva

Copy link
Copy Markdown
Member

Need to add you to the contributor team so you can read the build logs.

That check looks for an appropriate label, which I've added now.

didn't like how buildState was tacked on as another argument into every
function. This cleans up function signatures while still allowing us to
modify the build status in the `on_*` hook steps

Signed-off-by: Taylor Silva <[email protected]>
keeps the naming internally consistent. The "state" wording came from
the community user that submitted the suggestion

Signed-off-by: Taylor Silva <[email protected]>
@taylorsilva

Copy link
Copy Markdown
Member

Thanks for kicking off this PR!

I've reviewed the code and made some refactors to clean things up. I didn't like adding a third argument to all the functions, so I cleaned things up by introducing a planBuilder which takes 2/3 of the initial set of args. It's also clearer in the code that we only set build status for the on_* hook steps now.

The bigger UX decisions I made were the following:

  • Change env var name from BUILD_STATE to BUILD_STATUS because we refer to it as "build status" everywhere else in the code base
  • BUILD_STATUS is only set for the on_[failure/success/error/abort] hook steps. All other steps only ever saw BUILD_STATUS=started

I tried to see if there was an easy way to dynamically set BUILD_STATUS during execution of all the steps. Sadly it would involve a larger refactor. Because we're setting the status during the creating of the in-memory 'exec.Stepper` object, there's no way for us to easily inject the build status during runtime.


I manually verified this work by running this pipeline:

resources:
  - name: env
    type: mock

jobs:
  - name: job
    plan:
      - &print_env
        put: env
        no_get: true
        params:
          version: ok
          print_env: true
      - task: ref-local-vars
        config:
          platform: linux
          image_resource:
            type: mock
            source: {mirror_self: true}
          run:
            path: sh
            args:
              - -c
              - |
                echo Hello
                exit 1
    on_success: *print_env
    on_failure: *print_env
    ensure: *print_env
    on_error: *print_env
    on_abort: *print_env
image image image image

the status only changes when the hook steps are used, so I'd prefer to
set the precedent that only the on_* hook steps get the BUILD_STATUS env
var set. This avoids the situation where someone tries to use the
`ensure` hook step, which would only ever have `BUILD_STATUS=started`.

Signed-off-by: Taylor Silva <[email protected]>
@arakakimarcelo

Copy link
Copy Markdown
Contributor Author

Very nice your solution @taylorsilva.
Only thing left is to resolve the unit tests, right?

@taylorsilva

Copy link
Copy Markdown
Member

I'm expecting all PR checks to pass. Once they pass I'll merge.

@taylorsilva taylorsilva changed the title feat(atc): natively inject BUILD_STATE into resource metadata feat(atc): natively inject BUILD_STATUS into resource metadata Apr 14, 2026
@taylorsilva taylorsilva moved this from Todo to In Progress in Pull Requests Apr 14, 2026
@taylorsilva
taylorsilva merged commit 75773a5 into concourse:master Apr 14, 2026
12 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Pull Requests Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Make the build state available to resources via metadata

2 participants