Blog Posted June 5, 2017

Commiting Via the Concourse Git Resource

A Concourse resource is any entity that can be checked for new versions, fetched at a specific version, and/or pushed up to idempotently create new versions. Concourse's built-in git-resource is a Concourse resource for working with git repositories.

Pulling down a git repository for use in a pipeline job using the git-resource is fairly straight forward:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
resources:

- name: my-repo
  type: git
  source:
    branch: master
    uri: git@github.com:my-org/my-repo.git
    private_key: {{private_github_private_key}}

jobs:

- name: git-log
  plan:
  - get: my-repo
  - task: show-log
      config:
        inputs:
        - name: my-repo
        platform: linux
        image_resource:
          type: docker-image
          source:
            repository: node
            tag: 6.3.1
        run:
          path: bash
          args:
            - -exc
            - cd my-repo
            - git --no-pager log

But how can Concourse's git-resource functionality be leveraged to make and push commits to a repository? The following offers an example pipeline job executing a put on a modified git resource:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
resources:

- name: my-repo
  type: git
  source:
    branch: master
    uri: git@github.com:my-org/my-repo.git
    private_key: {{private_github_private_key}}

jobs:

- name: commit-and-push-to-repo
  plan:
  - get: my-repo
  - task: commit-and-push
      config:
        inputs:
        - name: my-repo
        outputs:
        - name: my-repo-modified
        platform: linux
        image_resource:
          type: docker-image
          source:
            repository: node
            tag: 6.3.1
        run:
          path: bash
          args:
            - -exc
            - git clone my-repo my-repo-modified
            - cd akamai-gtm-archive-modified
            - echo $(date) > date_file.txt
            - git add .
            - git commit -m "add new date_file.txt date"
  - put: my-repo
    params:
      repository: my-repo-modified