Skip to content

Add metadata from get steps to the local build var#9419

Merged
taylorsilva merged 1 commit intoconcourse:masterfrom
PentaHelix:master
Jan 22, 2026
Merged

Add metadata from get steps to the local build var#9419
taylorsilva merged 1 commit intoconcourse:masterfrom
PentaHelix:master

Conversation

@PentaHelix
Copy link
Contributor

@PentaHelix PentaHelix commented Jan 8, 2026

Changes proposed by this PR

Metadata from get steps are added to the local build var ((.:)) under the name of the get step. E.g.:

- get: repo

Will then have all it's metadata available under the var ((.:repo.<metadata-field-name)).

Example from CI:
image
Will then have the following vars available in the build for later steps to use:

  • ((.:repo.commit))
  • ((.:repo.author))
  • ((.:repo.author_date))
  • etc.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 8, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: PentaHelix / name: Jakob Kuen (1d1224e)

return nil
}

func AsMap(metadata []atc.MetadataField) map[string]any {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is probably a better place for this function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add it onto a new type of []MetadataField here:

type MetadataField struct {
Name string `json:"name"`
Value string `json:"value"`
}

Something like:

type Metadata []MetadataField

func (m Metadata) AsMap() map[string]any {
	result := make(map[string]any, len(m))
	for _, v := range m {
		result[v.Name] = v.Value
	}
	return result
}

Then VersionResult can also use that type:

type VersionResult struct {
Version atc.Version `json:"version"`
Metadata []atc.MetadataField `json:"metadata,omitempty"`
}

Then AsMap(versionResult.Metadata) would become versionResult.Metadata.AsMap()!

@taylorsilva
Copy link
Member

@PentaHelix Thanks for the PR! I have added you the all team in the concourse github org, which will allow you to see the build logs for the PR checks. You'll probably get an email to accept the invite.

@PentaHelix PentaHelix marked this pull request as ready for review January 11, 2026 09:01
@PentaHelix PentaHelix requested a review from a team as a code owner January 11, 2026 09:01
@taylorsilva
Copy link
Member

Thanks for the PR! Will review after I get 8.0 out.

Copy link
Member

@taylorsilva taylorsilva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I suggested how you can refactor AsMap() if you want to. As-is though, this works as expected.

Given this pipeline:

resources:
  - name: metadata
    type: mock
    source:
      metadata:
        - name: hello
          value: from metadata
        - name: hope
          value: it works!

jobs:
  - name: job
    plan:
      - get: metadata
      - task: echo
        config:
          platform: linux
          image_resource:
            type: mock
            source:
              mirror_self: true
          run:
            path: bash
            args:
              - -c
              - |
                echo ((.:metadata.hello))
                echo ((.:metadata.hope))

It worked!

image

If you don't have time to refactor I'll merge it as-is and refactor it later. Let me know. Thanks again for the PR!

return nil
}

func AsMap(metadata []atc.MetadataField) map[string]any {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add it onto a new type of []MetadataField here:

type MetadataField struct {
Name string `json:"name"`
Value string `json:"value"`
}

Something like:

type Metadata []MetadataField

func (m Metadata) AsMap() map[string]any {
	result := make(map[string]any, len(m))
	for _, v := range m {
		result[v.Name] = v.Value
	}
	return result
}

Then VersionResult can also use that type:

type VersionResult struct {
Version atc.Version `json:"version"`
Metadata []atc.MetadataField `json:"metadata,omitempty"`
}

Then AsMap(versionResult.Metadata) would become versionResult.Metadata.AsMap()!

@taylorsilva taylorsilva moved this from Todo to Waiting on Contributor in Pull Requests Jan 19, 2026
@kcbimonte
Copy link
Contributor

To prevent possible collisions with Local Vars, wonder if it'd be beneficial to use the resource name instead of a . to denote that it's coming from a resource instead of a local var.

Like if I have a local var in the job of metadata and the mock resource providing metadata, which one "wins"?

@taylorsilva
Copy link
Member

@PentaHelix asked about that too. My response: https://github.com/orgs/concourse/discussions/9417#discussioncomment-15479153

After this PR, if someone currently has a pipeline that has a get step with the same name as load_var step, nothing will functionally change for them. The load_var will overwrite the metadata.

The part before the colon is also meant to be used to refer to var_sources, so this would introduce a new risk of step names colliding with var_sources which I think is a worse situation to put users in.

@taylorsilva taylorsilva merged commit b606b60 into concourse:master Jan 22, 2026
12 checks passed
@github-project-automation github-project-automation bot moved this from Waiting on Contributor to Done in Pull Requests Jan 22, 2026
@taylorsilva taylorsilva changed the title get_step: add metadata to build vars Add metadata from get steps to the local build var Jan 22, 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.

3 participants