0

I want to write a script where I will pass the values and the script will update all the substitutions values automically. In cloud build trigger, I am passing values like _DOCKER_IMAGE, _IMAGE_TAG, _BUCKET_NAME etc. to the substitutions values of the cloud build trigger. I was looking into the documentation Gcloud command options for triggers but did not find any reference to update the substitutions values using gcloud command. I tried these commands but it was failed to execute.

gcloud beta builds triggers update <TRIGGER_NAME> --project=$PROJECT_ID --substitutions=_BUCKET_NAME=demo-bucket-name

gcloud alpha builds triggers update <TRIGGER_NAME> --project=$PROJECT_ID --substitutions=_BUCKET_NAME=demo-bucket-name

The error message I got:

ERROR: (gcloud.beta.builds.triggers) Invalid choice: 'update'. Maybe you meant:
gcloud beta builds triggers export
gcloud beta builds connections update github
gcloud beta builds connections update github-enterprise
gcloud builds cancel
gcloud builds describe
gcloud builds list
gcloud builds log
gcloud builds submit

2 Answers2

1

Despite update being in the documentation see here, it looks like gcloud builds triggers update isn't a valid command:

enter image description here

I did try running gcloud components update to see if gcloud was out of date however it didn't seem to make a difference

My only suggestion would be to try a delete then a create:

gcloud triggers delete <TRIGGER_NAME>
gcloud beta builds triggers create github \ 
--name=<TRIGGER_NAME> \
<TRIGGER_CONFIG> \
--substitutions=_BUCKET_NAME=demo-bucket-name
Ryan Jones
  • 21
  • 2
0

As mentioned in this document

To override the substitution value you specified in the build config file, use the --substitutions flag in the gcloud builds submit command. Note that substitutions are a mapping of variables to values rather than arrays or sequences. You can override default substitution variable values except for $PROJECT_ID and $BUILD_ID. The following command overrides the default values.

gcloud builds submit --config=cloudbuild.yaml \
 --substitutions=_BUCKET_NAME=demo-bucket-name


You can also check this documentation on Updating a build trigger which might help

Cloud Build trigger automatically starts a build whenever you make any changes to your source code. You can configure the trigger to build your code on any changes to the source repository or only changes that match certain criteria.

Sathi Aiswarya
  • 2,068
  • 2
  • 11
  • Thank you for your reply but It did not give me the exact answer I want. – Md. Omar Hasan Apr 22 '23 at 10:14
  • can you please elaborate why it didn't answer your question. did the above documentations not helpful? – Sathi Aiswarya Apr 24 '23 at 08:38
  • Not actually. I want to use gcloud command to update a substitution value of a trigger. Lets say. trigger name: demo-repo-build, substitution_value= _BUCKET_NAME=demo-bucket now i want to write a script, to put the command so that it will update the value of the substitution. Your command will work for one service, but i want command to work for multiple let's say 10+ triggers – Md. Omar Hasan Apr 26 '23 at 09:58
  • seems it is not possible since the substitutions are related to a specific build either by being specified in the cloudbuild.yaml config file or in the [--substitutions argument](https://cloud.google.com/sdk/gcloud/reference/builds/submit#--substitutions) flag for the gcloud command. – Sathi Aiswarya Apr 26 '23 at 13:19