CircleCI Configuration Introduction
CircleCI is a platform for Continuous Integration and Delivery which can be used to implement DevOps practice.
CircleCI Configuration Introduction
CircleCI believes in configuration as code. Consequently, the entire
delivery process from build to deploy is orchestrated through a single
file called config.yml
. The config.yml
file is
located in a folder called .circleci
at the top of your
repo project. CircleCI uses the YAML syntax for config.
Using the shell
CircleCI provides an on-demand shell to run commands. 1. Sign up with
CircleCI and select your Version Control System (VCS). 2. Create a
.circleci
folder at the root of your project. 3. Create a
config.yml
file inside the .circleci
folder
and paste and following code:
1 | version: 2.1 |
Explaining each line: 1. This indicates the version of the CircleCI
platform you are using. 2. The jobs
level contains a
collection of children, representing your jobs. You specify the names
for these jobs, for example, build
, test
,
deploy
. 3. build
is the first child in the
jobs
collection. In this example, build
is
also the only job. 4. This specifies that you are using a Docker image
for the container where your job's commands are run. 5. This is the
Docker image. 6. The steps
collection is a list of
run
directives. 7. Each run
directive is
executed in the order in which it is declared. 8. The name
attribute provides useful information when returning warnings, errors,
and output. 9. The command
attribute is a list of shell
commands that you want to execute. 10. Prints. 11. Prints. 4. Commit
your config.yml
file and push if you are working remotely.
5. On the projects page in CircleCI, find your project and click the
blue Set Up Project button next to it. 6. In the pop-up window, choose
the default Fastest option for selecting your config.yml
file. 7. CircleCI uses your config.yml
file to run the
pipeline. You can see the output in the CircleCI dashboard.
Using code from your repo
CircleCI provides several commands to simplify complex actions. In
this example, you will use the checkout
command. This
command fetches the code from your git repo. Once you have retrieved
that code, you can work with it in subsequent steps.
1 | version: 2.1 |
Using different environments and creating workflows
With CircleCI, you can run different jobs in different execution environments, such as virtual machines or Docker containers. By changing the Docker image, you can quickly upgrade your environment version or change languages.
1 | version: 2.1 |
Adding a manual approval
1 | version: 2.1 |
Configuring databases
PostgreSQL database testing example
1 | version: 2.1 |