We are using cloud build for continuous deployment on GCP. When pushing commits to fast (e.g. on development) the triggered builds are running in parallel. Sometimes those interfere which one another. For example when two app engine deployments are running at the same time.
Is there a way or best practise to force builds which are triggered from the same build trigger to run one after another?
Regards, Carsten
Using a cached Docker image. The easiest way to increase the speed of your Docker image build is by specifying a cached image that can be used for subsequent builds.
A build config file defines the fields that are needed for Cloud Build to perform your tasks. You'll need a build config file if you're starting builds using the gcloud command-line tool or build triggers. You can write the build config file using the YAML or the JSON syntax.
I've done this by adding an initial step on my cloudbuild.yaml
file. What it does is:
gcloud builds list --ongoing --format='value(id)' --filter="substitutions.TRIGGER_NAME=$TRIGGER_NAME"
.gcloud builds cancel ${on_going_build[i]}
to cancel the buildPlease see the cloudbuild.yaml
below
steps:
- id: "Stop Other Ongoing Build"
name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- -c
- |
on_going_build=($(gcloud builds list --ongoing --format='value(id)' --filter="substitutions.TRIGGER_NAME=$TRIGGER_NAME" | xargs))
for (( i=0; i<${#on_going_build[@]}; i++ )); do
if [ "$i" -gt "0" ]; then # skip current
echo "Cancelling build ${on_going_build[i]}"
gcloud builds cancel ${on_going_build[i]}
fi
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With