How to commit changes to git in Concourse build?
Asked Answered
P

1

10

During Concourse build of Java application I want to:

  1. Checkout git master branch
  2. Run mvn package
  3. If it was successful:
    • increment the SNAPSHOT version in Maven's pom.xml
    • commit it back to the master branch with [skip ci] commit message prefix
    • push local branch to the upstream

I haven't found the recommended way of dealing with git except git-resource, which can only get or put resources, but not produce new commits.

Polyhymnia answered 5/3, 2017 at 10:9 Comment(1)
You should take a look at Maven's release pluginLigamentous
H
17

You should make your commit inside of a task.

You do that by making a task which has your repo as an input, and declares a modified repo as an output. After cloning from input to output, change into your output folder, make your changes and commit.

Here's an example pipeline.yml:

resources:
- name: some-repo
  type: git
  source:
    uri: [email protected]:myorg/project

jobs:
- name: commit-and-push
  plan:
  - get: some-repo
  - task: commit
    config:
      platform: linux
      image_resource:
        type: docker-image
        source:
          repository: concourse/buildroot
          tag: git

      inputs:
      - name: some-repo

      outputs:
      - name: some-modified-repo

      run:
        path: /bin/bash
        args:
        - -c
        - |
          set -eux

          git clone some-repo some-modified-repo

          cd some-modified-repo
          echo "new line" >> some-file.txt

          git add .

          git config --global user.name "YOUR NAME"
          git config --global user.email "YOUR EMAIL ADDRESS"

          git commit -m "Changed some-file.txt"
  - put: some-repo  
    params: {repository: some-modified-repo}
Hashish answered 6/3, 2017 at 18:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.