Add metadata from get steps to the local build var#9419
Add metadata from get steps to the local build var#9419taylorsilva merged 1 commit intoconcourse:masterfrom
Conversation
|
|
| return nil | ||
| } | ||
|
|
||
| func AsMap(metadata []atc.MetadataField) map[string]any { |
There was a problem hiding this comment.
There is probably a better place for this function
There was a problem hiding this comment.
I'd add it onto a new type of []MetadataField here:
concourse/atc/resource_types.go
Lines 10 to 13 in e81401c
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:
concourse/atc/resource/resource.go
Lines 19 to 22 in e81401c
Then AsMap(versionResult.Metadata) would become versionResult.Metadata.AsMap()!
|
@PentaHelix Thanks for the PR! I have added you the |
|
Thanks for the PR! Will review after I get 8.0 out. |
taylorsilva
left a comment
There was a problem hiding this comment.
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!
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 { |
There was a problem hiding this comment.
I'd add it onto a new type of []MetadataField here:
concourse/atc/resource_types.go
Lines 10 to 13 in e81401c
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:
concourse/atc/resource/resource.go
Lines 19 to 22 in e81401c
Then AsMap(versionResult.Metadata) would become versionResult.Metadata.AsMap()!
|
To prevent possible collisions with Local Vars, wonder if it'd be beneficial to use the resource name instead of a Like if I have a local var in the job of metadata and the mock resource providing metadata, which one "wins"? |
|
@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 The part before the colon is also meant to be used to refer to |
Changes proposed by this PR
Metadata from
getsteps are added to the local build var((.:))under the name of the get step. E.g.:Will then have all it's metadata available under the var
((.:repo.<metadata-field-name)).Example from CI:

Will then have the following vars available in the build for later steps to use:
((.:repo.commit))((.:repo.author))((.:repo.author_date))