Understanding Jobs and Tasks in CircleCI

Overview

In CircleCI, the terms task and job refer to different components of the build process. Understanding these concepts is crucial to effectively configure your CI/CD pipeline in CircleCI.

Jobs

A job in CircleCI is the smallest configurable unit within a config.yml file. Each job is an independent entity that defines the build environment and the series of steps to be performed within that environment.

Jobs are defined in the jobs: section of the config.yml file. A job can be as simple as running a shell command, or it can involve complex build processes involving multiple commands, caching, and artifacts.

Here is an example of a simple job:

version: 2.1
jobs:
  build:
    docker:
      - image: circleci/ruby:2.4.1
    steps:
      - checkout
      - run: echo "A first hello"

In this example, a job named build is defined. It uses a Docker image with Ruby version 2.4.1 and runs two steps: checking out the code from the current repository and running a simple echo command.

Tasks

In CircleCI, a task refers to a single execution of a job. If a job has parallelism configured, CircleCI will run that job multiple times in parallel, and each execution of the job is considered a task.

For example, if you have a job with parallelism: 6 in your config.yml file, CircleCI will run six tasks for that job. Each task will execute the same series of steps defined in the job, but they will run independently and in parallel.

Here is an example of a job with parallelism:

version: 2.1
jobs:
  test:
    docker:
      - image: circleci/ruby:2.4.1
    parallelism: 6
    steps:
      - checkout
      - run: ./run-tests.sh

In this example, the test job is defined with parallelism: 6, so CircleCI will run six tasks for this job. Each task will execute the ./run-tests.sh script independently and in parallel.

 

Additional Resources

Was this article helpful?
1 out of 1 found this helpful

Comments

0 comments

Article is closed for comments.