3

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?

Myles McDonnell
  • 12,943
  • 17
  • 66
  • 116

2 Answers2

6

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
phillbaker
  • 1,518
  • 11
  • 22
  • To account for potential multiple simple tags on the same commit, and take the last one: `git tag -l --points-at HEAD | tail -n 1` – piroux Sep 09 '20 at 08:23
1

phillbaker's solution works in theory, but it needs some modifications to work on the current (august 2020) version of Concourse. This is a snippet from the pipeline I built using his code as starting point:

resources:
- name: git-walangtext
  type: git
  source:
    uri: git@bitbucket.org:wall-art/walangtext.git
    branch: master
    private_key: |
      {{ bitbucket_walangtext_private_key }}

- name: walangtext-docker-image
  type: docker-image
  source:
    email: {{ email }}
    username: {{ username }}
    password: {{ secret_docker_hub_password }}
    repository: wallartnl/walangtext

jobs:
- name: walangtext
  serial: true
  plan:
  - get: git-walangtext
    trigger: true
  - task: generate-tag
    config:
      platform: linux
      image_resource:
        type: docker-image
        source:
          repository: concourse/git-resource
      inputs:
        - name: git-walangtext
      run:
        path: sh
        args:
        - -c
        - |
          cd git-walangtext
          git describe --tags --abbrev=0 > tag
      outputs:
        - name: git-walangtext
  - put: walangtext-docker-image
    params:
      build: git-walangtext/src/WALangtextSite
      dockerfile: git-walangtext/src/WALangtextSite/Docker/Dockerfile
      tag_file: git-walangtext/tag
      tag_as_latest: true

Note that the git-resource image is way too large for the simple action it performs, I'm still looking for a much smaller image.

Another note is that I need to adjust the git command to my situation: I need to get the last tag, not the tag exactly at HEAD.

Sebastiaan M
  • 5,775
  • 2
  • 27
  • 28