In this article, I'm a Circle CI beginner, and I'll summarize how to run Circle CI in the cloud environment (run a test every time you push with git).
Circle CI can be linked with two services, GitHub and Bitbucket, but I think that there are more links with GitHub, so I will describe how to do it here.
As a method, please press the link button from the CircleCI site while logged in to ** GitHub ** and proceed according to the procedure.
After authentication on GitHub is completed, create a GitHub project (repository) on CircleCI as well. It seems that the method of adding a project is different depending on whether it is a personal repository, an organization repository, or a private repository, but here, the method for personal + public repository is described.
Ultimately, the goal is to run CircleCI in a cloud environment. To do this, we'll start by running it in a local environment.
A ** job ** is a collection of steps.
** Step ** is a list of commands executed by CircleCI.
You can run tests to build an execution environment from scratch by running a job, delete it when you're done, and so on. This area is an introductory knowledge of CircleCI, so it is easy to understand by referring to the following articles.
I've just started CircleCI, so I've summarized it in an easy-to-understand manner
Let's create an environment for local job execution!
Jobs are executed in the local environment using the Circle CLI. Circle CLI runs on the Docker container, so if you haven't installed Docker yet, install it first. By the way, with CircleCI, if you have basic knowledge of Docker, it is basically okay, so it is recommended to work after touching Docker lightly.
Now, type the following command to install it.
Terminal
~ % curl -fLSs https://circle.ci/cli | bash
If the installation is successful, the following message will be displayed.
Terminal
Starting installation.
Installing CircleCI CLI v0.1.5879
Installing to /usr/local/bin
/usr/local/bin/circleci
The CircleCI CLI installation is complete. However, if you see the following message, you need to update.
Terminal
You are running 0.1.5879
A new release is available (0.1.6949)
You can update with `circleci update install`
When this message is displayed, execute the circleci update install
command to update.
You need to create a .circleci folder
in your app directory and a config.yml file
in that directory to do the job.
If you do not write the correct syntax in YAML format in this file, you will not be able to execute the top part.
Execute the following commands in order.
Terminal
% mkdir -p .circleci
% touch .circleci/config.yml
If you have successfully created it, you can check the following with the ls -al
command.
Terminal
total 0
drwr-xr-x 3 xxxxx xxx 96 8 3 18:13 .
drwr-xr-x 20 xxxxx xxx 640 8 3 18:11 ..
drwr-xr-x 2 xxxx xxx 64 8 3 18:13 .circlci
If it is displayed like this, it is successful.
The CircleCI CLI provides commands to check for syntax and configuration errors. For example, ruby's CircleCI syntax is as follows. This notation is a slightly customized version of the official one. ** The notation is officially prepared for each language **, so please check it.
ruby:.circleci/config.yml
version: 2.1
orbs:
ruby: circleci/[email protected]
jobs:
build:
docker:
- image: circleci/ruby:2.6.5-stretch-node
executor: ruby/default
steps:
- checkout
- run: gem install bundler:2.2.3
- run:
name: Which bundler?
command: bundle -v
- ruby/bundle-install
If you try to execute the validation command on this, you will see how.
Terminal
% circleci config validate
config file at .circleci/config.yml is valid.
If it is displayed like this, there is no error and you can see that the grammar and settings are correct. By the way, if there is an error, the following will be displayed.
Terminal
Error:ERROR IN CONFIG FILE
Cause of error
Create a file, write it, and run it once before running!
Use the circleci local execute
command to execute the job.
Terminal
% circleci local execute
Docker image digest: sha256:9c32926d78c37f0c050a02dd13dc1596b6e4621b1df9362cd51368fb957951a0
#abridgement
====>> Preparing environment variables
Using build environment variables:
BASH_ENV=/tmp/.bash_env-localbuild-1609201012
CI=true
CIRCLECI=true
CIRCLE_BRANCH=
CIRCLE_BUILD_NUM=
CIRCLE_JOB=build
CIRCLE_NODE_INDEX=0
CIRCLE_NODE_TOTAL=1
CIRCLE_REPOSITORY_URL=
CIRCLE_SHA1=
CIRCLE_SHELL_ENV=/tmp/.bash_env-localbuild-1609201012
CIRCLE_WORKING_DIRECTORY=~/project
#abridgement
Post-install message from sass:
Ruby Sass has reached end-of-life and should no longer be used.
* If you use Sass as a command-line tool, we recommend using Dart Sass, the new
primary implementation: https://sass-lang.com/install
* If you use Sass as a plug-in for a Ruby web framework, we recommend using the
sassc gem: https://github.com/sass/sassc-ruby#readme
* For more details, please refer to the Sass blog:
https://sass-lang.com/blog/posts/7828841
Success!
If you see Success!
, Your local job is successful.
Once done, try pushing your changes on Github. Next, let's go to the CircleCI site and check it. If the [success] part of the image below is [Runnin], it means that you are running the test. If this display is [Failed], there is an error, so let's check the error.
This is the end of environment construction.
"Introduction to CircleCI Practice-Both development speed and quality brought about by CI/CD"
Recommended Posts