0
0
Dockerdevops~5 mins

GitLab CI with Docker - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: GitLab CI with Docker
O(n)
Understanding Time Complexity

We want to understand how the time to run a GitLab CI pipeline using Docker changes as we add more jobs or steps.

How does the total execution time grow when the pipeline gets bigger?

Scenario Under Consideration

Analyze the time complexity of the following GitLab CI snippet using Docker.


image: docker:latest

services:
  - docker:dind

stages:
  - build
  - test

build_job:
  stage: build
  script:
    - docker build -t myapp .

test_job:
  stage: test
  script:
    - docker run myapp pytest

This pipeline builds a Docker image and then runs tests inside a container from that image.

Identify Repeating Operations

Look for repeated steps or loops in the pipeline.

  • Primary operation: Each job runs its script commands sequentially.
  • How many times: The pipeline runs each job once per pipeline execution; no loops inside the snippet.
How Execution Grows With Input

As we add more jobs or steps, the total time grows roughly by adding each job's time.

Input Size (number of jobs)Approx. Operations (job runs)
22 jobs run sequentially
1010 jobs run sequentially
100100 jobs run sequentially

Pattern observation: The total time grows linearly as more jobs are added.

Final Time Complexity

Time Complexity: O(n)

This means the total pipeline time grows in direct proportion to the number of jobs.

Common Mistake

[X] Wrong: "Adding more jobs will not increase total time because they run in parallel."

[OK] Correct: In this example, jobs run in stages sequentially, so total time adds up, not stays the same.

Interview Connect

Understanding how pipeline steps add up helps you design efficient CI/CD workflows and explain your choices clearly.

Self-Check

What if we changed the pipeline to run all jobs in parallel? How would the time complexity change?