Search code examples
google-cloud-platformgcloudslackgoogle-cloud-pubsub

Custom Message for GCP Slack Build Notification


I followed this tutorial to successfully setup GCP Slack build notification. Right now, I have the following Slack message:

// createSlackMessage creates a message from a build object.
const createSlackMessage = (build) => {
  const message = {
    text: `Build \`${build.id}\``,
    mrkdwn: true,
    attachments: [
      {
        title: 'Build logs',
        title_link: build.logUrl,
        fields: [{
          title: 'Status',
          value: build.status
        }]
      }
    ]
  };
  return message;
}

In addition to what's here, I also want to have information like project ID, the user who deployed it and other environment variables I am using during deployment (e.g. I use _ENV to distinguish dev server and production server). What is the way to extract such information? Where can I find the reference to the list of objects build object has? If build doesn't have my desired object by default, can I add that somehow?


Solution

  • Have a look here, there you have all the options available that you can use.

    Hope this helps.

    UPDATE:

    Not sure if you can add custom variables, but I think substitutions might be what you are looking for.

    Use substitutions in your build config file to substitute specific variables at runtime. Substitutions are helpful for variables whose value isn't known until build time, or to re-use an existing build request with different variable values.

    Cloud Build provides built-in substitutions or you can define your own substitutions. Use the substitutions field in your build's steps and images fields to resolve their values at build time.

    Here you have more information about them.

    Let me know.