Search code examples
goslackgoogle-cloud-build

Pass Repository Name to Slack bot during Cloud Build


I am following the documentation to get a Slack bot to report on Cloud Build progress for a Project in Google Cloud Platform, using the Slack image found in Google Cloud Builder Community. I've been able to get the out-of-the-box messages to post successfully.

Since I have multiple repositories that will get built, I want to post the name of the Repository that is being built:

e.g.

Build bot: Repo Fizz-buzz built successfully...
Build bot: Repo Wizz-bang failed to build...

In the Notify() function, the cloudbuild.Build struct has a few properties that might do what I am wanting. The Source.RepoSource.RepoName looks ideal, but it's nil.

Another option would be to have the trigger() function add the repository name as an argument:

Args: []string{
                    fmt.Sprintf("--build=%s", build),
                    fmt.Sprintf("--webhook=%s", webhook),
                    fmt.Sprintf("--repoName=%s", repoName),
                    "--mode=monitor",
                },

I'd prefer to have the Notify() function handle this, but I haven't found the appropriate struct property.

Is there a property that I can use during the notify() function to pass along the repository name?


Solution

  • I use github app triggered builds and use build.substitutions.REPO_NAME