Skip to content

Instantly share code, notes, and snippets.

@nk-gears
Last active June 25, 2020 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nk-gears/e2b865e1a3eb9ee03e5ad05949b29e88 to your computer and use it in GitHub Desktop.
Save nk-gears/e2b865e1a3eb9ee03e5ad05949b29e88 to your computer and use it in GitHub Desktop.
CloudBuild Automated Triggers
https://codelabs.developers.google.com/codelabs/cloud-builder-gke-continuous-deploy/index.html#1
cat <<EOF > branch-build-trigger.json
{
"triggerTemplate": {
"projectId": "${PROJECT}",
"repoName": "default",
"branchName": "[^(?!.*master)].*"
},
"description": "branch",
"substitutions": {
"_CLOUDSDK_COMPUTE_ZONE": "${ZONE}",
"_CLOUDSDK_CONTAINER_CLUSTER": "${CLUSTER}"
},
"filename": "builder/cloudbuild-dev.yaml"
}
EOF
curl -X POST \
https://cloudbuild.googleapis.com/v1/projects/${PROJECT}/triggers \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud config config-helper --format='value(credential.access_token)')" \
--data-binary @branch-build-trigger.json
cat <<EOF > master-build-trigger.json
{
"triggerTemplate": {
"projectId": "${PROJECT}",
"repoName": "default",
"branchName": "master"
},
"description": "master",
"substitutions": {
"_CLOUDSDK_COMPUTE_ZONE": "${ZONE}",
"_CLOUDSDK_CONTAINER_CLUSTER": "${CLUSTER}"
},
"filename": "builder/cloudbuild-canary.yaml"
}
EOF
curl -X POST \
https://cloudbuild.googleapis.com/v1/projects/${PROJECT}/triggers \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud config config-helper --format='value(credential.access_token)')" \
--data-binary @master-build-trigger.json
cat <<EOF > tag-build-trigger.json
{
"triggerTemplate": {
"projectId": "${PROJECT}",
"repoName": "default",
"tagName": ".*"
},
"description": "tag",
"substitutions": {
"_CLOUDSDK_COMPUTE_ZONE": "${ZONE}",
"_CLOUDSDK_CONTAINER_CLUSTER": "${CLUSTER}"
},
"filename": "builder/cloudbuild-prod.yaml"
}
EOF
curl -X POST \
https://cloudbuild.googleapis.com/v1/projects/${PROJECT}/triggers \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud config config-helper --format='value(credential.access_token)')" \
--data-binary @tag-build-trigger.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment