To exclusively obtain the PR version from a Git branch in Concourse, you can use the following steps:
Set up a resource with the Git source and the pull_request property set to true, like this:
resources:
- name: pr-source
type: git
source:
uri: git://github.com/your-org/your-repo.git
branch: master
pull_request: true
Use the get step to fetch the latest version of the resource:
jobs:
- name: build
plan:
- get: pr-source
trigger: true
- ...
Use the metadata output in subsequent steps to get the PR version:
jobs:
- name: build
plan:
- get: pr-source
trigger: true
version: {pr: true}
- put: output-resource
params:
output_file: pr-source/metadata.json
- ...
You can then parse the metadata output to get the PR version.
resources:
- name: output-resource
type: ...
source:
...
- name: parse-pr-version
type:...
source:
...
check_every: 30s # Or a period long enough to allow the output-resource put to complete.
tags: [docker]
inputs:
- name: output-resource
outputs:
- name: pr-version
run:
path: sh
args:
- -xec
- |
# Parse the PR version from the output-resource metadata file
version=$(jq -er '.version.ref' ${{inputs.output-resource}}/metadata.json | sed 's#refs/pull/##')
echo "{ \"version\": { \"pr\": \"$version\" } }" > ${{outputs.pr-version}}/version.json
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-05-05 11:00:00 +0000
Seen: 8 times
Last updated: Aug 10 '22