Continuous integration using Google Cloud Build

Cloud Build helps build software quickly across all languages. If your cloud provider is Google it's a better option compared to other CI providers out there.
Using Cloud Build it's really easy to create pipelines as part of your build steps to automate the deployment.
In this article, we would look into a very simple case, We configure cloud build to run our build on every time there is a commit to our Github Pull request.
Step 1. Build and debug your cloud build setup locally.
Step 2. Setup triggers in your project to trigger on every GitHub pull request commit.
Build and debug your cloud build setup locally.
First, let's clone our GitHub repo and run it locally.
git clone https://github.com/pravanjan/my-node-example.git
cd my-node-example
npm install
npm test
After running the test command you must have seen, to make our example simple the project has only one API endpoints.

We have written one test case to confirm its working as expected.

Now we would look into our cloudbuild.yaml file which would run defined steps every time it receives a pull request commit. To understand this file we need to know two things steps: contain the build steps that you want to run. name: point it to a container image to execute your task

- esThe local build can build only on Linux and macOS. Please do install gcloud SDK to carry on this step.
//install the cloud-build-local
gcloud components install cloud-build-local
//run build locally.
cloud-build-local --config=cloudbuild.yaml --dryrun=false --substitutions=SHORT_SHA="demo" .
to know more about cloud build local https://cloud.google.com/cloud-build/docs/build-debug-locally
Now that we have validated our cloudbuild.yaml file let's configure the same in our google cloud project.
— Setup trigger in your project to trigger on every GitHub pull request commit.
Open the google cloud build page https://console.cloud.google.com/cloud-build/triggers/connect

The next step is to select your source code provider and authenticate the repo. In this example, we are using Github repo.

Now setup the build trigger

As we see we have selected the trigger type as a Pull request and configure to trigger any change commit to the pull request.
That's it done!!!. Now every time we create a new branch from master and create a pull request or commit to pulling request. That would automatically trigger a build and our cloud build would make sure all test cases are passes through and create images for deployment.