Skip to content

Make the build state available to resources via metadata #8541

Closed

Description

@marco-m-pix4d

When using a Concourse resource as notification mechanism (say to update the GitHub Commit status, or to send a chat message), the configuration is verbose and redundant, also if "optimised" with YAML anchors. For example:

cogito-handlers: &cogito-handlers
    on_success:
      put: cogito
      # redundant: I am telling the resource that the state is `success`, but the handler is `on_success`
      params: {state: success}
    on_failure:
      put: cogito
      # same redundancy for all the other handlers
      params: {state: failure}
    on_error:
      put: cogito
      params: {state: error}
    on_abort:
      put: cogito
      params: {state: abort}

Then this YAML anchor is referenced in the rest of the pipeline:

jobs:
  - name: autocat
    <<: *cogito-handlers
    plan:
      - get: repo.git
    ...

When running the put step, the resource has already access to the following resource metadata:

  • $BUILD_ID
  • $BUILD_NAME
  • $BUILD_JOB_NAME
  • $BUILD_PIPELINE_NAME
  • $BUILD_PIPELINE_INSTANCE_VARS
  • $BUILD_TEAM_NAME
  • $BUILD_CREATED_BY
  • $ATC_EXTERNAL_URL

By looking at the metadata, I realized that the resource has enough information to query the ATC, get the build state associated to the $BUILD_ID and allow the configuration to be less verbose and more natural:

cogito-handlers: &cogito-handlers
    on_success:
      put: cogito
    on_failure:
      put: cogito
    on_error:
      put: cogito
    on_abort:
      put: cogito

But querying the ATC adds another possibility for failure and especially requires to provide to the resource the local credentials of a Concourse user. Also if the user can be restricted to read-only access via the viewer role, it is still giving the resource more permissions than it really needs.

Thus the proposal: if we added to the resource metadata the build state, say

  • $BUILD_STATE

we could gain the reduced verbosity shown above without the complexity and risk of giving user credentials to the resource.

Regarding #6600, in my understanding it would require so many other changes (prototypes and notification itself) that I don't see it happening soon.

Activity

  1. marco-m commented on Sep 10, 2022

    @marco-m
    Contributor

    Hello @xtremerui, opinions? :-)

  2. kallisti5 commented on Feb 14, 2023

    @kallisti5

    I'd strongly support this. It would greatly assist in #8686 as well

  3. evanchaoli commented on Feb 16, 2023

    @evanchaoli
    Contributor

    To clarify, on_success etc. hooks can be used on any step. Only when they are used at job level, they may get BUILD_STATE.

    I just quickly checked related code, technically it's possible to add this feature.

  4. taylorsilva commented on Jan 7, 2025

    @taylorsilva
    Member

    This is a great idea! Anyone is free to open a PR implementing this. I'll review and merge it.

  5. analytically commented on Apr 22, 2025

    @analytically
    Contributor

    Image

    I suggest we set 'BUILD_STATUS' as env var as it's more commonly used and more intuitive?

    const (
    	BuildStatusPending   BuildStatus = "pending"
    	BuildStatusStarted   BuildStatus = "started"
    	BuildStatusAborted   BuildStatus = "aborted"
    	BuildStatusSucceeded BuildStatus = "succeeded"
    	BuildStatusFailed    BuildStatus = "failed"
    	BuildStatusErrored   BuildStatus = "errored"
    )
    

    I can open a PR?

  6. moved this from Icebox to Backlog in Concourse Roadmapon Feb 13, 2026
  7. added a commit that references this issue on Apr 12, 2026
    03bd3fa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions