wordpress - 如何创建可重用的 CircleCI 松弛 ORB
问题描述
正如 circleCI 开发人员所知道的那样,circleCi 通知被贬低以支持 ORB。
我需要启用 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,staging,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,staging,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,staging,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,staging,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文件如下::
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,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
- xxxxxxxxxx
- run:
name: Install composer inside root directory
command: composer install -n
# - 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-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,staging,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,staging,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,staging,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,staging,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
推荐阅读
- python - 为颜色数据实现萤火虫算法
- javascript - 有没有办法在不打开 Outlook 或 Apple Mail 的情况下使用 CSS(或任何与 Web 开发相关的语言)中的“mailto”立即发送电子邮件?
- python - 如何在 Linux 上访问环境变量值 Python?
- regex - 使用 perl 插入可能丢失的行
- git - 删除(意外)和重新定位本地仓库(Git)后无法推送到 Heroku
- visual-studio - 在 Visual Studio Pro 2017 中启动 Azure Function 时出错
- kotlin - 使用 webflux 进行上下文日志记录(标头中的关联 ID)
- android - 在 Xamarin.Android 中使用新的 Google Place API 创建自定义地点选择器
- rust - 宏扩展忽略标记 `let` 和任何后续
- c++ - Visual Studio Code C/C++ Extension 没有为编译器设置包含路径