How can Cloud Build take dynamic parameters to increment a registry tag?

隐身守侯 提交于 2019-12-11 16:28:04

问题


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?


回答1:


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...



来源:https://stackoverflow.com/questions/59118037/how-can-cloud-build-take-dynamic-parameters-to-increment-a-registry-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!