# Google Cloud Build

{% hint style="info" %}
This is an older version of the document. To view the most recent version of the document, click [here](https://docs.opsmx.com/products/orchestration-module-opsmx-enterprise-for-spinnaker-oes/additional-feature-configuration/add-ci-system/steps-to-configure-ci-systems/google-cloud-build).
{% endhint %}

## Steps to Setup Google Cloud Build <a href="#steps-to-setup-google-cloud-build" id="steps-to-setup-google-cloud-build"></a>

* This (Cloud Build) is a service that executes builds on GCP infrastructure. Cloud Build can import source code from GCS, Cloud Storage Repo’s, GitHub or BitBucket and execute a build as per the configurations and provide artifacts such as Java archives or docker containers.
* Using this CI system on Spinnaker, enables Spinnaker to trigger pipelines upon completion on builds.
* **Prerequisites**:
  1. Ensure to have a valid GCP with a Cloud Build API. API can be enabled with the gcloud command as below

     ```
     gcloud services enable cloudbuild.googleapis.com
     ```
* **Configure Spinnaker for Google Cloud Build Pub/Sub Notifications:**
* Google Cloud Build sends [Build Notifications](https://cloud.google.com/cloud-build/docs/send-build-notifications) when the state of your build changes. Create a pipeline trigger to invoke a pipeline based on the status of your build.
  1. Create a Subscription Object for the cloud-builds topics in your project

     ```
     PROJECT_ID=
     SUBSCRIPTION_NAME=googleCloudBuilds

     gcloud pubsub subscriptions create $SUBSCRIPTION_NAME \
     --topic projects/$PROJECT_ID/topics/cloud-builds \
     --project $PROJECT_ID
     ```
  2. Configure Google Cloud Build for Spinnaker, using Halyard by executing the following command

     ```
     hal config pubsub google subscription add $SUBSCRIPTION_NAME \
     --project $PROJECT_ID \
     --subscription-name $SUBSCRIPTION_NAME \
     --message-format GCB

     hal config pubsub google enable
     ```
  3. Deploy Spinnaker post execute Steps #1 & #2

     ```
     hal deploy apply
     ```
  4. Steps to Configure Google Cloud Build Pipeline
     * In your Pipeline configuration, click the Configuration stage on the far left of the pipeline.
     * Click Automated Triggers.
     * In the Type field, select Pub/Sub.
     * In the Pub/Sub System Type field, select google.
     * In the Subscription Name field, select your $SUBSCRIPTION\_NAME value.
     * In the Attribute Constraints field, enter status in the Key, and SUCCESS (all upper case) in the Value field.
     * In the Payload Constraints field, you can enter any of the top-level fields from the Build object documentation as the key, and a Java regular expression as the value.
     * In the Expected Artifacts field, you can add any build artifacts as expected artifacts. For example, if the build produces a Docker image, you can add an expected artifact of type Docker with a value of [gcr.io/my-project-id/my-](http://gcr.io/my-project-id/my-) application:tag (replacing my-project-id, my-application, and tag with appropriate values). You can then use the produced image in downstream stages.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.opsmx.com/opsmx-1/opsmx-context-engine/additional-resources/previous-releases/isd-3.10/orchestration-module-opsmx-enterprise-for-spinnaker-oes/additional-feature-configuration/add-ci-system/steps-to-configure-ci-systems/google-cloud-build.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
