Ask Your Question
0

What is the method to exclusively obtain the PR version from a Git branch in Concourse?

asked 2021-05-05 11:00:00 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-08-10 08:00:00 +0000

huitzilopochtli gravatar image

To exclusively obtain the PR version from a Git branch in Concourse, you can use the following steps:

  1. 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
    
  2. Use the get step to fetch the latest version of the resource:

    jobs:
    - name: build
     plan:
     - get: pr-source
       trigger: true
     - ...
    
  3. 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
    
edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2021-05-05 11:00:00 +0000

Seen: 8 times

Last updated: Aug 10 '22