Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a Google Cloud Build trigger via cli / rest api / cloud functions?

Is there such an option? My use case would be running a trigger for a production build (deploys to production). Ideally, that trigger doesn't need to listen to any change since it is invoked manually via chatbot.

I saw this video CI/CD for Hybrid and Multi-Cloud Customers (Cloud Next '18) announcing there's an API trigger support, I'm not sure if that's what I need.

like image 381
chriz Avatar asked Aug 19 '18 06:08

chriz


1 Answers

I did same thing few days ago.

You can submit your builds using gcloud and rest api

gcloud:

gcloud builds submit --no-source  --config=cloudbuild.yaml --async --format=json

Rest API:

Send you cloudbuild.yaml as JSON with Auth Token to this url https://cloudbuild.googleapis.com/v1/projects/standf-188123/builds?alt=json

example cloudbuild.yaml:

steps:

- name: 'gcr.io/cloud-builders/docker'
  id: Docker Version
  args: ["version"]

- name: 'alpine'
  id:  Hello Cloud Build
  args: ["echo", "Hello Cloud Build"]

example rest_json_body:

{"steps": [{"args": ["version"], "id": "Docker Version", "name": "gcr.io/cloud-builders/docker"}, {"args": ["echo", "Hello Cloud Build"], "id": "Hello Cloud Build", "name": "alpine"}]}
like image 87
manikantanr Avatar answered Sep 20 '22 12:09

manikantanr