How the triggers are added to Queue in google cloud build?

旧时模样 提交于 2020-08-10 23:54:36

问题


Build trigger should wait untill the previous trigger for a same repos finishes its execution.

If i push twice to the repo, trigger executed twice at same time. I don't want this to be happen.

How to make the cloud trigger to wait for the previous trigger job?

Thanks in advance!


回答1:


You would have to implement this configuration and logic. It would have to evaluate if the build has been triggered and running and then wait for it to finish.

Maybe something can be done in order to check with the buildSteps and a waitFor or with a custom builder.

A combination between a call to the API and listing the Cloud Builds and they're statuses, implementing maybe waitFor in your config so it checks and then proceed with the build once the other is finished.

The thing is depending on how many builds you are submitting I don't have a clear idea on how you can assign a priority in the queue as it would go FIFO.

Someone else added a similar question here

Hope this helps.




回答2:


There's nothing "out of box" for this as stated above.

The only two things I could think of are:

  1. adding an initial step that queries the builds using gcloud builds list and filtering by trigger-id (you'd have to set this manually as I don't think you can get this from the build itself as a variable). Then check if there is more than 1 build running, sleep for whatever, and check again. The only thing you have to watch out for is after the checking again, if a new build starts you need to have a way of distinguishing that (again since we don't know the build-id) and your build... or you will end up with a continuous loop and no builds.

  2. The idea would be to have a storage bucket and each build to create a file with some sort of naming convention so we can build a "queue" system. At the beginning of each build, we would mount the storage, search for any other files, and then create ours.

Example:

  • First build -- no other builds, we create file 'build-name-1" ... we then start building, and at the end, we delete that file.
  • Second build (while the first is running), we mount the storage, check for other files, we see that there is one file, so we create a new file incrementing the last number (build-name-2) and sleep... we wait until this file is not there, and then we can start our build, and at the end, delete the file again.
  • (and so on for three, four, etc)


来源:https://stackoverflow.com/questions/59783816/how-the-triggers-are-added-to-queue-in-google-cloud-build

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