This article is about some kind of automated testing and how to notify slack of the results of automated deployment. We've put it together in a way that's easy, easy to understand, and quick, so let's get it done and do something different! !!
CircleCI 2.1
orbs: slack: circleci/[email protected]
If you meet these conditions, follow the procedure for the first time. If this is not the case, be aware that it can cause confusion when an error occurs!
https://slack.com/services/new/incoming-webhook
⬆️⬆️ Please get the URL to set in the environment variable from the above URL. After logging in to the specified account and specifying the channel to notify, the URL will be issued.
When you log in, the screen for selecting a channel will appear in the above picture, so select it. The URL will appear on the next screen, so copy it and make a note of it.
Set environment variables in CircleCI. Register environment variables on the project setting screen Select a project and import
name is SLACK_WEBHOOK Value copy and paste the URL you wrote down earlier
config.yml
orbs:
slack: circleci/[email protected]
#abridgement
- slack/status:
success_message: ':circleci-pass: $CIRCLE_BRANCH build is complete\n:github_octocat: User:$CIRCLE_USERNAME'
failure_message: ':circleci-fail: $CIRCLE_BRANCH build failed\n:github_octocat: User:$CIRCLE_USERNAME'
webhook: '${SLACK_WEBHOOK}'
Make these two types of description
My situation
config.yml
version: 2.1
orbs:
slack: circleci/[email protected]
jobs:
build:
docker:
- image: circleci/ruby:2.6.5-node-browsers
environment:
- BUNDLER_VERSION: 2.2.3
- RAILS_ENV: 'test'
- image: circleci/mysql:5.7
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
- MYSQL_ROOT_HOST: '127.0.0.1'
working_directory: **
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "Gemfile.lock" }}
- v1-dependencies-
- run:
name: install dependencies
command: |
gem install bundler -v 2.2.0
bundle install --jobs=4 --retry=3 --path vendor/bundle
- save_cache:
paths:
- ./vendor/bundle
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
# Database setup
- run: mv ./config/database.yml.ci ./config/database.yml
# Database setup
- run:
name: DatabaseSetup
command: |
bundle exec rake db:create
bundle exec rake db:schema:load
# yarn install
- run:
name: yarn Install
command: yarn install
- run: bundle exec bin/webpack
# run tests!
- run:
name:RSpec parallel execution
command: |
mkdir /tmp/test-results
TEST_FILES="$(circleci tests glob " **/spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
bundle exec rspec --format progress \
--out /tmp/test-results/rspec.xml \
--format progress \
$TEST_FILES
# collect reports
- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results
destination: test-results
#ssh connection
- add_ssh_keys:
fingerprints:
- "**"
#Deploy
- deploy:
name: Capistrano deploy
command: |
if [ "${CIRCLE_BRANCH}" != "master" ]; then
exit 0
fi
bundle exec cap production deploy
- slack/status:
success_message: ':circleci-pass: $CIRCLE_BRANCH build is complete\n:github_octocat: User:$CIRCLE_USERNAME'
failure_message: ':circleci-fail: $CIRCLE_BRANCH build failed\n:github_octocat: User:$CIRCLE_USERNAME'
webhook: '${SLACK_WEBHOOK}'
If you run a job with this and get a notification, it is successful.
When you receive this notification, you are done. Thank you for your hard work! !!
Recommended Posts