git - 只有当特定分支在 CircleCI 中失败时,我才能获得通知?
问题描述
master
如果分支在 CircleCI 中失败,我希望收到通知。
有用户请求添加此功能,但没有评论就关闭了- 所以我不知道 Circle 是否添加了该功能。
我可以filter
在 Configuration Reference中看到,但这些似乎只存在于整个工作流程中——我想filter
只是其中的notify
一部分。
config.yml
包括在下面。
version: 2.1
orbs:
node: circleci/node@4.0.0
slack: circleci/slack@4.0
executors:
docker-node-12:
docker:
- image: cimg/node:12.19
full-app:
resource_class: 2xlarge
docker:
- image: cimg/node:12.19
- image: elasticsearch:6.4.3
- image: circleci/postgres:10-ram
- image: circleci/redis:6
jobs:
install npm packages:
executor: docker-node-12
steps:
- checkout
- node/install-packages
- persist_to_workspace:
root: /home/circleci/project
paths:
- .
run tests:
description: Run App's tests
# https://circleci.com/docs/reference-2-1/#docker
parameters:
filter:
description: "Test filter for jest"
default: ""
type: string
executor: full-app
steps:
- attach_workspace:
at: /home/circleci/project
- run:
name: Run tests
command: |
cd /home/circleci/project; set -o allexport; cp .env.circleci .env; source .env
npx jest --passWithNoTests --runInBand --logHeapUsage << parameters.filter >>
notify:
docker:
- image: "cimg/base:stable"
steps:
- slack/notify:
custom: |
{
"blocks": [
{
"type": "section",
"fields": [
{
"type": "plain_text",
"text": "Oh no, master failed!",
"emoji": true
}
]
}
]
}
event: always
workflows:
install_and_test:
jobs:
- install npm packages
- run tests:
requires:
- install npm packages
matrix:
parameters:
filter:
- --testPathPattern='a'
- --testPathPattern='b'
- notify:
context: slack-secrets
解决方案
您可以branch_pattern
按照文档使用。
steps:
- slack/notify:
channel: $SLACK_CHANNEL
event: fail
template: basic_fail_1
branch_pattern: main
推荐阅读
- javascript - JQuery在功能中禁用单页滚动
- python-3.x - 如何在一帧中同时调整多个不同尺寸的图像?
- java - 如何在 pom.xml 中指定 python 文件版本?
- mongodb - 将 Mongo Atlas 与 Spring boot 连接时出现问题(我已经尝试了所有 stackoverflow 解决方案)
- django - Django按日期范围过滤,如果日期中没有记录,则返回其中的虚拟记录,而不会死在循环中
- amazon-s3 - 使用 aws java sdk 在 amazon s3 glacier 中创建一个新文件夹
- laravel - Laravel 8 在斜杠上行为不端
- javascript - 为什么这个 React.useEffect() 代码不安全?
- iframe - 在 iframe 中加载 Next.js 路由在 Vercel 上失败
- c# - 加载 Roslyn 生成的程序集时出现 ReflectionTypeLoadException