git - 仅当 CircleCI 中的特定分支失败时,如何才能收到通知?

标签 git continuous-integration circleci

如果 CircleCI 中的 master 分支失败,我希望收到通知。

有一个user request to add this feature, but it was closed without comment - 所以我不知道 Circle 是否添加了该功能或没有添加它。

我可以看到有filter in the Configuration Reference ,但这些似乎只存在于整个工作流程中 - 我想过滤通知部分。

config.yml 包含在下面。

version: 2.1

orbs:
  node: circleci/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b6d8d9d2d3f68298869886" rel="noreferrer noopener nofollow">[email protected]</a>
  slack: circleci/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="01726d60626a41352f31" rel="noreferrer noopener nofollow">[email protected]</a>

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

最佳答案

您可以按照documentation使用branch_pattern .

steps:
  - slack/notify:
      channel: $SLACK_CHANNEL
      event: fail
      template: basic_fail_1
      branch_pattern: main

关于git - 仅当 CircleCI 中的特定分支失败时,如何才能收到通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65005894/

相关文章:

android - 我应该将 Ionic Platforms 文件夹放入源代码管理吗?

git - 本地 GIT 仓库的 SCM URL

unit-testing - dotnet test 仅测试解决方案上的项目

javascript - Cypress 测试运行程序通过在 circleCI 中带有信号 SIGSEGV 的退出事件意外退出

cron - 如何在 yaml 文件中的 cron 中使用 0/10?

git - 使用 git add -A 后,.gitignore 被跟踪

git - 与 git 的意外 merge 冲突

Azure DevOps 管道 CI/CD

continuous-integration - 根据条件提前终止构建规范,特别是在 git 标签上

ruby - 在 CircleCI 中指定 Puppet + Ruby 版本矩阵