[CircleCI] Running Your First Build

Tram Ho

CI / CD is a pair of jobs that involve automating repetitive tasks by developers, including CI (Continuous Integration) and CD (Continuous Delivery), which means integration. more often, faster when code and regularly updated new versions (delivery).

CircleCI is a product that implements both CI / CD, in particular it builds, tests the scripts you install and tests (unit tests) for example and automatically deploys the application – Continuous Deploy.

CircleCI automates your software builds, tests, and deployments.

CircleCI runs nearly 1 million jobs every day, supporting 30,000 organizations. These organizations choose CircloCI because jobs run fast and application builds can be optimized for speed. CircleCI can be configured to run multiple complex pipelines effectively.

For a developer, you can also use SSH into any joib to debug build issues, install jobs in parallel to run faster, and config caching with a few simple keywords to reuse data from. previous jobs via workflow.

For administrators and administrators, using CircleCI installed on a shared server, CircleCI provides an intuitive interface for monitoring your build.

The document provides step-by-step instructions for you to build your first success on Circle 2.0

0. Required before first build build

  • Basic knowledge of Git, with GitHub.com account, GitHub repository
  • Have a basic knowledge of terminal or bash to use the command line effectively

1. Createting a Repository

Step 1: Select repositories and click New or go directly to this page https://github.com/new

Step 2: Select Initialize this repository with a README and click Create repository button:

2. Add a .yml file

Circle uses 1file YAML to determine how you want to test the environment and test what you want to run. In Circle 2.0 , this file must be called config.yml and must be in the hidden .circleci folder. On Mac, Linux and Windows, the names of files and folders starting with a dot will be pressed according to the default settings.

And the content of config.yml file

Then commit and push to the repo as usual

Or you can create with skins

3. Setting up Your Build on CircleCI

  • Step 1: Before performing this step you need to create a CircleCI account. Then go to the Dashboard page.
  • Step 2: Next you will get the option to list the projects you can access and build CircleCI. On the next screen, you can add the repo you created as a new project on CircleCI
  • Step 3: To add your new repo, click Set Up project

  • Step 4: On the next screen, you will get several configuration options for your project on CircleCI. Choose the right one and click Start building

4. Running Your First CircleCI Build!

You should watch the build run automatically and pass! So, what’s going on? Click on the blue Success button on the Dashboard to review the runs.

  • Spin up environment : CircleCI used circleci / ruby: 2.4.1. Docker image to launch a virtual computing environment.
  • Checkout code : CircleCI checked out your GitHub repository and “cloned” into the virtual environment launched in Step 1.
  • echo : Here are the other commands in the config.yml file: CircleCI runs the echo command with inpuit “A first hello”. Although there is actually no source code on your repo and actually not configured the tests in the config.yml file, CircleCI still considers your build to be “successful” because all steps have been successful (returned). 0). In fact, many projects are much more complex, usually there will be multiple Docker images and many steps, including a large number of tests.

5. Breaking Your Build!

Edit the config.yml file on GitHub and create a new commit to make a new build. If the build fails, there will be a red Failed button and CircleCI will send you an email to notify the error.

6. Using the Workflows Functionality

The next tutorial will show you how to use workflow, a strength of CircleCI to build jobs in parallel or need to depend on each other.

  • Step 1: To view the workflow, edit the .circleci/config.yml file

  • Step 2: Next, rename the 2 jobs to a different name. In this example we will name them one and two . Change the echo content differently too. To have time between csac last build, we can add the sleep command.
  • Step 3: Add the workflows section to the config.yml file. This part can be placed anywhere in the file. But it is usually placed at the beginning or the end of the file:

  • Step 4: Commit this change, push it to your repository and look again at the CircleCI dashboard

  • Step 5: Click the link to see the workflow 2 jobs running in parallel

See more workflow at: https://circleci.com/docs/2.0/workflows/#overview

7. Adding Some Changes to use the Workspaces Functionality

Each workflow needs a workspace link, which can be used to move files from the top jobs to the workflow they’re processing. You can use the workflow to do this.

8. SSH into Your Build

If you are more comfortable with the terminal, you can use SSH directly to the CircleCI jobs to handle the problem with builds by running the build again with the SSH enabled option.

Using this method is also very convenient for you to debug your jobs, great is not it.

Note that you will need to add your SSH keys to your GitHub account: https://help.github.com/articles/connecting-to-github-with-ssh/ .

OK then, you can copy the generated shh command and access it

So you are executing this job as a command line. You can use the commands in the workspace only:

summary

  • To integrate CircleCI application, simply, create the configuration file .circleci/config.yml and the configuration on Dashboard is https://circleci.com/dashboard
  • If you just run simple jobs like check 1 convention, unit tests, without setting too much content will be fairly simple files, including run of steps are being

  • If there are more jobs, consider using jobs and workflows (for example, you just want to check tests and want to deploy, for example).
  • Use SSH to debug jobs, access the container to test.
  • The commands in CircleCI can completely refer to environment variables, allowing you to work more extensively!

References

CircleCI – Get started

Share the news now

Source : Viblo