google-cloud-platformgoogle-container-builder

Google Cloud Container Builder share data between steps?


I need the short git commit sha (git rev-parse --short HEAD) for one of my build steps. I do not see any other way than to actually use the git builder, and then use the output in the docker build step. The below outputs what I need, and I would like to store that value in COMMIT_SHA_SHORT and use it in next build step. Is this possible somehow?

steps:
- name: 'gcr.io/cloud-builders/git'
  args: ['rev-parse', '--short', 'HEAD']

Solution

  • You can use Container Builder Custom Build [1].

    A custom build step is a container image that the Container Builder worker VM pulls and runs with your source volume-mounted to /workspace. Your custom build step can execute any script or binary inside the container; as such, it can do anything a container can do.

    [1] https://cloud.google.com/container-builder/docs/create-custom-build-steps