2

I want my Cloud Build to push an image to a registry with an incremented tag. So, when the trigger arrives from GitHub, build the image, and if the latest tag was 1.10, tag the new one 1.11. Similarly, the 1.11 value will serve in multiple other steps in the build.

Reading the registry and incrementing the tag is easy (in a bash Cloud Build step), but Cloud Build has no way to pass parameters. (Substitutions come from outside the Cloud Build process, for example from the Git tags, and are not generated inside the process.)

This StackOverflow question and this article say that Cloud Build steps can communicate by writing files to the workspace directory.

That is clumsy. But worse, this requires using shell steps exclusively, not the native docker-building steps, nor the native image command.

How can I do this?

Joshua Fox
  • 18,704
  • 23
  • 87
  • 147
  • 1
    I think the question you referenced is indeed the answer. I think what you are asking for is an alternate solution but I don't think we will find one. – Kolban Nov 30 '19 at 17:42
  • Thank you. So Cloud Build seems very limited. I can see its usefulness in a CI pipeline, but not in response to triggers on its own – Joshua Fox Dec 01 '19 at 09:59

1 Answers1

6

Sadly you can't. The Cloud Builder image have each time their own sandbox and only the /workspace directory is mounted. By the way, all the environment variable, binaries installed and so, doesn't persist from one container to the next one.

You have to use the shell script each time :( The easiest way is to have a file in your /workspace directory (for example env.var file)

# load the environment variable
source /workspace/env.var
# Add variable
echo "NEW=Variable" >> /workspace/env.var

For this, Cloud Build is boring...

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • Thank you. So Cloud Build seems very limited. I can see its usefulness in a CI pipeline, but not in response to triggers on its own – Joshua Fox Dec 01 '19 at 10:00
  • 2
    Cloud Build was previously named Container Builder and that would still be an appropriate name. Though it *can* do other things, the one thing it is good at is building an image, without complex pipeline logic. – Joshua Fox Dec 01 '19 at 13:43
  • I agree. This Env Var limitation is the very big pain point on Cloud Build. It's perfect for the rest, but this is very frustrating! – guillaume blaquiere Dec 01 '19 at 19:48