Get started Bring yourself up to speed with our introductory content.

Learn to run a CI pipeline with this Google Cloud Build tutorial

If you want to build a CI/CD pipeline on Google Cloud Platform, Google Cloud Build is a good place to start.

Google Cloud Build is a continuous integration service that uses Docker containers with preinstalled tools and software versions to run command-line builds serverlessly. It works with any source control repository service that Google Cloud Platform can connect to, such as GitHub, Bitbucket or Google's own Cloud Source Repositories. The only requirement is to set a YAML or JSON file in the repository with the build instructions. The files are simple and include a minimum of two parameters: the container to be used and the build instructions to run on that container.

Each step is going to start the container specified in the configuration file, run the arguments to that container as if it were from the command line, then destroy the container. This means you can run multiple build instructions with different tools. For example, one step could run a Docker build while another runs pytest or another unit testing framework. In addition, this entire process can be done without having to configure or set up a build server or servers for each of these dependencies.

However, there are some trade-offs to this approach, since each step runs in a separate container. For starters, any artifacts or metadata that are generated during the build process must be persisted outside of the build server, such as saving Docker containers to a container registry or sending test results to a file share or source control system.

Cloud Build does offer the logs generated by each container in the pipeline in a central location with a clearly identifiable label to show which step the logs came from for easy tracking, but the best practice is to persist artifacts and test results in a separate system.

Finally, it is also possible to run custom containers with custom build steps and tools. In this case, the only other parameters to specify are an entry point for the container to execute commandsand the location of the container from the container registry in question.

Follow the Google Cloud Build tutorial above to learn how to build a CI/CD pipeline using the Cloud Build in conjunction with Cloud Source Repositories.

View All Videos
Transcript - Learn to run a CI pipeline with this Google Cloud Build tutorial

Hello, today we're going to go over how to set up a cloud build CI/CD pipeline using GCP Cloud Build and cloud source repositories. To start off, I have a cloud source repository here on GCP. And it's got three files in it.

The first is quickstart.sh. This is just simple HelloWorld. Next is the Docker file, which we're going to use to build our container. And this is just taking alpine, copying the Quickstart shell script over and then running it. And lastly, I have cloudbuild.YAML. This is going to be the basis for my pipeline.

Each one of these steps is going to become a build step later on. So on line two we have cloud-builders/docker. This is a prebuilt Docker container with all of the tools necessary to run a Docker build. And there are several of these, depending on which language and version you need to use. I will throw a link to the GitHub repository where these are stored into the snip description. But that container is going to take the Docker build commands as an argument. So in this case, on line three, 'build' '-t' with our repository name, and then it's going to generate a Docker image and upload it to GCR, which is there on line five.

So now that that's set up, let's go over to Cloud Build. Okay, I'm here in Cloud Build and the first thing I want to do is go under triggers. And let's go over here to connect a repository for a moment. You can see that we have a few options here to connect Bitbucket or GitHub or use a Cloud Source Repository natively. Just so you know, some of these are still in beta at the time of this recording, which is why we're using Cloud Source Repository. But it is possible to do this through GitHub or Bitbucket as well.

Let's go ahead and click here to create a trigger. Now, if we wanted to go back to the triggers page and click on Create trigger at the top of the screen here, it would bring us to the same spot. But let's go ahead and select our repository. We will call this trigger 'Hello trigger.' And we can leave the description the same, what this is going to do is it's going to detect a push from any branch and use that to trigger our build. So if we look a little bit here under trigger type, that's where we see we're looking for a branch under branch (regex). We're looking that's a regex we can use for the branch naming convention. So if you have feature or bug fix in your branch names, you can filter those out as well and only build those.

And then we're going to scroll down a little bit and under build a configuration file, we're going to use that and select cloud-build.YAML, which lives at the root of our repository. And we also have the ability to add some more variables into here, but we're going to skip that because this is just a demo. Let's go ahead and create that trigger. And we see it here under our active repository triggers, we can go ahead and run it directly from here. And let's go ahead and click Show, it will take us over to the build itself, under cloud build. All right, our build is successful. And we have the logs down here to confirm that. So now our Docker container is built. And we can go back to our build triggers. And if we enable or disable the trigger here that will control whether the build runs in the first place. All right, that's it. Thank you for watching.

+ Show Transcript
Data Center
ITOperations
SearchAWS
SearchVMware
Close