问题描述
CircleCI开发人员知道,为支持ORB,CircleCi通知已弃用。
我需要启用Slack通知,并已开始使用circleci/slack@3.4.2
软件包
我的circleCI config.yml文件包含x条命令,如下所示:
commands:
build-mu-plugins:
steps:
- run:
name: Clone mu-plugins
command: |
git clone git@github.com:Automattic/vip-go-mu-plugins.git mu-plugins && cd mu-plugins && git submodule update --init --recursive && cd ..
# - ORB Message
- slack/status:
fail_only: true
only_for_branches: develop,staging,master
failure_message: ':red_circle: $CIRCLE_USERNAME your Job $CIRCLE_JOB failed build-mu-plugins'
webhook: $SLACK_WEBHOOK
build-base-composer:
steps:
- add_ssh_keys:
fingerprints:
# CircleCI Fingerprint in newsuk repo
- fxxxxxxxx99:c5:2c
- run:
name: Install composer inside root directory
command: composer install -n
# - ORB Message
- slack/status:
fail_only: true
only_for_branches: develop,master
failure_message: ':red_circle: $CIRCLE_USERNAME your Job $CIRCLE_JOB failed build-base-composer'
webhook: $SLACK_WEBHOOK
build-wp-simple-saml:
steps:
- run:
name: Install composer packages for wp-simple-saml
command: composer install --no-dev --working-dir=plugins/wp-simple-saml/ -n --prefer-dist
# - ORB Message
- slack/status:
fail_only: true
only_for_branches: develop,master
failure_message: ':red_circle: $CIRCLE_USERNAME your Job $CIRCLE_JOB failed build-wp-simple-saml'
webhook: $SLACK_WEBHOOK
原则上,上述方法有效,但是由于每个- slack/status
都差不多,因此我想知道是否存在在EACH命令中配置ORB的更有效方法
可以
- slack/status:
fail_only: true
only_for_branches: develop,master
failure_message: ':red_circle: $CIRCLE_USERNAME your Job $CIRCLE_JOB failed build-base-composer'
webhook: $SLACK_WEBHOOK
放入参数或类似参数中,以便我可以重复而不必在每个命令中都定义所有ORB
也许类似
**orb-message** <<
- slack/status:
fail_only: true
only_for_branches: develop,master
failure_message: ':red_circle: $CIRCLE_USERNAME your Job $CIRCLE_JOB failed build-base-composer'
webhook: $SLACK_WEBHOOK
commands:
build-mu-plugins:
steps:
- run:
name: Clone mu-plugins
command: |
git clone git@github.com:Automattic/vip-go-mu-plugins.git mu-plugins && cd mu-plugins && git submodule update --init --recursive && cd ..
# - ORB Message
- **orb-message**
对于CircleCI来说我还很陌生,但是正在努力寻找关于此的一些文档
我完整的circleCI文件在::: p下
version: 2.1
orbs:
slack: circleci/slack@3.4.2
commands:
build-mu-plugins:
steps:
- run:
name: Clone mu-plugins
command: |
git clone git@github.com:Automattic/vip-go-mu-plugins.git mu-plugins && cd mu-plugins && git submodule update --init --recursive && cd ..
# - ORB Message
- slack/status:
fail_only: true
only_for_branches: develop,master
failure_message: ':red_circle: $CIRCLE_USERNAME your Job $CIRCLE_JOB failed build-mu-plugins'
webhook: $SLACK_WEBHOOK
build-base-composer:
steps:
- add_ssh_keys:
fingerprints:
# CircleCI Fingerprint in newsuk repo
- xxxxxxxxxx
- run:
name: Install composer inside root directory
command: composer install -n
# - ORB Message
- slack/status:
fail_only: true
only_for_branches: develop,master
failure_message: ':red_circle: $CIRCLE_USERNAME your Job $CIRCLE_JOB failed build-wp-simple-saml'
webhook: $SLACK_WEBHOOK
build-academy-composer:
steps:
- run:
name: Install composer inside academy theme
command: |
composer install --working-dir=themes/newsacademy/ -o -n
composer --working-dir=themes/newsacademy/ php:lint
# - ORB Message
- slack/status:
fail_only: true
only_for_branches: develop,master
failure_message: ':red_circle: $CIRCLE_USERNAME your Job $CIRCLE_JOB failed build-academy-composer'
webhook: $SLACK_WEBHOOK
build-nuk-newsuk-okta-plugin:
steps:
- run:
name: Install composer packages for News UK OKTA Plugin
command: composer install --no-dev --working-dir=plugins/nuk-wp-okta-plugin/ -n --prefer-dist --optimize-autoloader
- run:
name: Lint nuk-wp-okta-plugin
command: composer php:lint-okta
# - ORB Message
- slack/status:
fail_only: true
only_for_branches: develop,master
failure_message: ':red_circle: $CIRCLE_USERNAME your Job $CIRCLE_JOB failed build-nuk-newsuk-okta-plugin'
webhook: $SLACK_WEBHOOK
build-plugin-loader:
steps:
- run:
name: Install composer packages for News UK OKTA Plugin
command: composer php:lint-plugin-loader
# - ORB Message
- slack/status:
fail_only: true
only_for_branches: develop,master
failure_message: ':red_circle: $CIRCLE_USERNAME your Job $CIRCLE_JOB failed build-plugin-loader !'
webhook: $SLACK_WEBHOOK
jobs:
build:
docker:
- image: circleci/php:7.3-node-browsers
steps:
- checkout
- build-mu-plugins
- build-base-composer
- build-nuk-newsuk-okta-plugin
- build-plugin-loader
- build-academy-composer
- build-wp-simple-saml
#- run: npm install
#- run: npm run build
#- run: vendor/bin/phpunit
# TODO: Configure build steps here ^^^^^
- persist_to_workspace:
root: ./
paths:
- ./
deploy:
docker:
- image: circleci/php:7.3-node-browsers
steps:
- attach_workspace:
at: ./
- checkout
- add_ssh_keys:
fingerprints:
# CircleCI Deploy Fingerprint in wpcomvip repo
- xxxxxxxxxx
- run:
name: Deploy -built branch to github
command: bash <(curl -s "https://raw.githubusercontent.com/Automattic/vip-go-build/master/deploy.sh")
- slack/status:
fail_only: false
#channel: 'CS70KQ92N' use this if you want to deliver to a different channel other than the hook
only_for_branches: master
success_message: ':ok_hand: JOB $CIRCLE_JOB has been successful deploying to production'
failure_message: ':red_circle: JOB $CIRCLE_JOB has failed deploying to production!'
webhook: $SLACK_WEBHOOK
# Sync job runs every time to ensure we keep the News UK repository in sync with the VIP repo
sync:
docker:
- image: cimg/base:2020.01
steps:
# Run standard checkout to get the appropriate SSH keys installed,but then remove afterwards
- checkout:
path: checkout-tmp
- run:
name: Cleanup temporary checkout
command: rm -rf checkout-tmp
# Do the actual mirror & sync
- run:
name: Mirror clone from VIP repository
command: git clone --mirror ${CIRCLE_REPOSITORY_URL} readonly
- run:
name: Remove GitHub PR references
# https://stackoverflow.com/questions/37985275/how-can-i-exclude-pull-requests-from-git-mirror-clone/39764408#39764408
command: cd readonly && git show-ref | cut -d ' ' -f2 | (grep 'pull' || true) | xargs -r -L1 git update-ref -d
- add_ssh_keys:
fingerprints:
# CircleCI Sync Fingerprint in newsuk repo
- xxxxxxxxxxx
- run:
name: Add the News UK repository as the readonly remote
command: cd readonly && git remote add readonly git@github.com:newsuk/nuk-newsuk-wp.git
- run:
name: Push mirror to News UK (readonly) repository
command: cd readonly && git push --mirror readonly
workflows:
version: 2
sync:
jobs:
- sync
build_deploy:
jobs:
- build:
filters:
branches:
only:
- staging
- develop
- master
- deploy:
requires:
- build
filters:
branches:
only:
- master
- staging
- develop
解决方法
好吧,我明白了
我可以在命令中运行命令,因此 定义为
commands:
orb-message:
steps:
- slack/status:
fail_only: true
only_for_branches: develop,staging,master
failure_message: ':red_circle: $CIRCLE_USERNAME Job $CIRCLE_BRANCH failed'
webhook: $SLACK_WEBHOOK
build-mu-plugins:
steps:
- run:
name: Clone mu-plugins
command: |
git clone git@github.com:Automattic/vip-go-mu-plugins.git mu-plugins && cd mu-plugins && git submodule update --init --recursive && cd ..
# - ORB Message
- orb-message
并在其他命令中使用 orb-message