Set Up Slack Alerts for Job Results
We can set up Slack alerts for job results by defining reporter_config in the job definition. This is possible for all job types: periodics, presubmits, and postsubmits.
Prowgen is capable of adding this to the job definition.
Warning
Currently, it is still possible to manually add thereporter_config to periodic jobs. This functionality is deprecated, and using Prowgen is preferred.
Once a significant number of jobs have migrated to use Prowgen, the ability to manually edit the periodics will be removed.For example, by the above snippet, a Slack alert will be sent out to #forum channel when there is a failure of the job. The alert is formatted by report_template.
- The channel has to be in coreos.slack.com.
- The channel has to be public. If it is not then the
@prowbot has to be added to it otherwise it won’t be able to properly post messages. - The state in
job_states_to_reporthas to be a valid Prow job state. See upstream documentation. - The value of
report_templateis a Go template and it will be applied to the Prow job instance. The annotations such as{{.Spec.Job}}will be replaced by the job name when the alert is received in Slack. See upstream documentation for more fields of a Prow job. Note that no alerts will be sent out if the template is broken, e.g., cannot be parsed or applied successfully.
Setting up Slack notifications with Prowgen
Prowgen is the tool that is used to generate ProwJobs from ci-operator configuration. It is possible to instruct Prowgen to add a reporter_config to specific jobs.
Doing so requires creating or updating the repo (or organization) in question’s .config.prowgen file. This YAML configuration file is stored in the repo’s ci-operator folder.
For example, ci-tools configuration file is found at ci-operator/config/openshift/ci-tools/.config.prowgen. The following example illustrates how to utilize this config to add slack notifications for jobs:
| |
Note
Note that it is possible to include multipleslack_reporter entries in this config, but each job_name should only be included in, at most, one.Note
It is possible to add slack reporting for theimages postsubmit job by adding the “images” entry to job_names.Once the configuration is added, simply use the make jobs target to generate the new job definitions containing the reporter_config.
Slack Reporter Configuration
The slack_reporter configuration supports flexible job matching with multiple approaches:
- Exact matching with
job_names: Matches job names exactly - Pattern matching with
job_name_patterns: Matches job names using regular expressions - Exclusion with
excluded_job_patterns: Excludes jobs matching regex patterns (similar toexcluded_variants)
Matching Priority:
- Exclusions are checked first - if a job matches any
excluded_job_patterns, it’s excluded regardless of other rules - Exact matches in
job_namestake precedence over pattern matches injob_name_patterns - This allows for more flexible job matching while maintaining compatibility with existing configurations
Examples:
| |
The excluded_job_patterns approach is often simpler than complex inclusion patterns, especially when you want to match most jobs in a repository but exclude specific types.
The SlackReporterConfig is provided for reference.