Using `git commit` in Google Cloud Container Builder

141 Views Asked by At

How do I commit a new file to a git repo in Container Builder? The build step seems pretty straightforward:

{
    "name": "gcr.io/cloud-builders/git",
    "args": ["commit", 
            "--author=\"David\ Wynn\ <[email protected]>\"",
            "-am", 
            "Test post"]
}

... but the resulting command wraps the --author in a way that isn't valid:

commit "--author="David Wynn <[email protected]>"" -am "Test post"

Is there another way to pass in an author when committing? Is there an explicit "don't quote this" command for container builder?

Update 01

Edmund below suggests that breaking the equals sign apart should fix this, but the error for an unknown user still gets thrown. The Stack Overflow question here:

Commit without setting user.email and user.name

... suggests this is because the author flag doesn't update the committer, which is required. The new long form should be something like this:

git -c user.name='Paul Draper' -c user.email='[email protected]' commit -m '...'

.... but this brings us back to the original problem because Container Builder doesn't seem able to take a space-separated argument without quoting the whole piece.

Update 02 (Resolved)

For some reason, git seems fine when taking quoted strings for the -c flags, and as such this now works fine in container builder. The step now looks like the following :

{
  "name": "gcr.io/cloud-builders/git",
  "args": ["-c",
          "user.name=\"David\ \Wynn\"",
          "-c",
          "user.email=\"[email protected]\"",
          "commit", 
          "-m", 
          "Test post"]
},
2

There are 2 best solutions below

1
On

Splitting the argument into two parts (--author, value) should fix this problem. You can do this for any argument in git that the manual says should be in format "--argument=value".

{
    "name": "gcr.io/cloud-builders/git",
    "args": ["commit", 
            "--author",
            "\"David\ Wynn\ <[email protected]>\"",
            "-am", 
            "Test post"]
}
0
On

As posted in the update, git apparently takes quoted string on -c flags, so this now passes in container builder without issue using the following step:

{
  "name": "gcr.io/cloud-builders/git",
  "args": ["-c",
          "user.name=\"David\ \Wynn\"",
          "-c",
          "user.email=\"[email protected]\"",
          "commit", 
          "-m", 
          "Test post"]
},