Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to properly deploy a release replacing previous defective one

I have this pipeline which is supposed to be updated once a push is done.  Here's the cloudbuild.yaml file that should build the new code and deploy to the pipeline:

 

 

# Build and tag Docker images
- name: 'gcr.io/k8s-skaffold/pack'
entrypoint: 'pack'
args:
[
"build", "--builder=gcr.io/buildpacks/builder", "--publish", "us-central1-docker.pkg.dev/my-project/docker-repo/my-project-staging:$SHORT_SHA", "--env=GOOGLE_ENTRYPOINT=flask run"
]

- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: gcloud
args:
[
"deploy", "releases", "create", "release-${SHORT_SHA}",
"--delivery-pipeline", "staging-pipeline",
"--region", "us-central1",
"--annotations", "commitId=${REVISION_ID}",
"--images", "staging-image=us-central1-docker.pkg.dev/my-project/docker-repo/my-project-staging:$SHORT_SHA"
]

 

 
Since I'm building it from scratch, both build and deploy get some errors here and there. But sometimes when I push some new code to test a correction, Cloud Build gives me the following error:
 
Uploading tarball of [.] to [gs://5ab97cc8958b4855a3ca3ad7b7366eae_clouddeploy/source/1677270496.103914-264a45a8a7614e67851aebb2f5d297f4.tgz]
ERROR: (gcloud.deploy.releases.create) ALREADY_EXISTS: Resource 'projects/my-project/locations/us-central1/deliveryPipelines/staging-pipeline/releases/release-22df310' already exists
- '@type': type.googleapis.com/google.rpc.ResourceInfo
resourceName: projects/my-project/locations/us-central1/deliveryPipelines/staging-pipeline/releases/releases-22df310
 
It seems like even though new code was pushed, the release's short SHA is the same as the previous one. Is there a way to replace the previous, defective release with the current so I don't get this error?
 
Solved Solved
0 3 743
1 ACCEPTED SOLUTION

According to this documentation, SHORT_SHA is always referenced to the first seven characters of COMMIT_SHA. I would suggest to properly configure your substitute variables or manually provide a value to it. 

View solution in original post

3 REPLIES 3

Hi @alexandre-br ,

Just to confirm, you want to replace the previous release on your pipeline? What's the reason why you don't want to create a new release version instead of replacing the previous one?

Hi @marcanthonyb , I actually want to create a new release, but the error suggests it already exists (which is odd, since the release's name is created by a ${SHORT_SHA} value, so it shouldn't exist). 

According to this documentation, SHORT_SHA is always referenced to the first seven characters of COMMIT_SHA. I would suggest to properly configure your substitute variables or manually provide a value to it.