gitconcourseconcourse-git-resource

Concourse git-resource ; accessing a Git Tag to use on a docker-image put


I'm using https://github.com/concourse/git-resource with a tag_filter to trigger a release build. I need to access the tag name of the tag that triggered the build in order to use it during the build process and also to use it to tag the docker image resource put action. How might I do this?

I can run git tag -l --points-at HEAD > tag to get the tag for the build process but how would I then access it for the tag property of the docker-image put?


Solution

  • The tag parameter of the docker-image-resource is set up to take the path to a file containing the name of the tag. A common pattern is to set it to tag: a-git-resource/.git/HEAD to tag the produced docker image with the git sha.

    To get a specific name, an intermediate step would probably work:

    jobs:
      - name: build-docker-image
        plan:
          - get: a-git-resource
          - task: prep-for-build
            image: a-linux-of-your-choice-image
            config:
              platform: linux
              inputs:
                - name: a-git-resource
              run:
                path: sh
                args: |
                  cd a-git-resource
                  git tag -l --points-at HEAD > tag
          - put: docker-image-resource
            params:
              tag: a-git-resource/tag
              tag_as_latest: true
              build: a-git-resource