Jenkins to GitHub Actions path - Time & Space Complexity
When moving from Jenkins to GitHub Actions, it is important to understand how the time to run your automation changes as your tasks grow.
We want to see how the execution time grows when running a Jenkins pipeline compared to a similar GitHub Actions workflow.
Analyze the time complexity of the following Jenkins pipeline snippet.
pipeline {
agent any
stages {
stage('Build') {
steps {
script {
for (int i = 0; i < params.NUM_STEPS; i++) {
echo "Building step ${i}"
}
}
}
}
}
}
This pipeline runs a build stage that repeats a simple echo command a number of times based on input size.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: The for-loop running the echo command.
- How many times: It runs exactly NUM_STEPS times, which depends on input size.
The number of echo commands grows directly with NUM_STEPS.
| Input Size (NUM_STEPS) | Approx. Operations (echo commands) |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: If you double NUM_STEPS, the number of echo commands doubles too.
Time Complexity: O(n)
This means the time to run grows linearly with the number of steps you want to perform.
[X] Wrong: "Adding more steps won't affect the total time much because each step is simple."
[OK] Correct: Even simple steps add up, so more steps mean more total time, growing linearly.
Understanding how your automation scales helps you design better pipelines and workflows, a skill valued in real projects and interviews.
"What if we parallelize the steps instead of running them one by one? How would the time complexity change?"
Practice
Solution
Step 1: Understand Jenkins workflow storage
Jenkins typically stores job configurations on its own server, separate from the code repository.Step 2: Understand GitHub Actions workflow storage
GitHub Actions stores workflow YAML files directly inside the code repository under the .github/workflows directory.Final Answer:
GitHub Actions stores workflow files inside the repository, Jenkins uses an external server. -> Option BQuick Check:
Workflow location = repository for GitHub Actions [OK]
- Thinking Jenkins stores configs in the repo
- Assuming GitHub Actions uses external servers only
- Confusing storage locations for both tools
Solution
Step 1: Recall GitHub Actions trigger syntax
The correct YAML syntax uses 'on:' followed by the event type and branches list.Step 2: Match syntax to options
on: push: branches: [main] matches the correct YAML format: 'on: push: branches: [main]'. Others are invalid YAML or incorrect keywords.Final Answer:
on: push: branches: [main] -> Option AQuick Check:
Trigger syntax = 'on:' keyword [OK]
- Using 'trigger' instead of 'on' keyword
- Incorrect YAML indentation or keywords
- Confusing event names and branch filters
on:
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Run tests
run: echo "Tests running..."Solution
Step 1: Analyze the trigger section
The workflow triggers on pull_request events targeting the 'main' branch only.Step 2: Understand job execution
When a pull request is opened against 'main', the job runs the steps: checkout and echo test message.Final Answer:
The workflow runs only when a pull request targets the main branch. -> Option AQuick Check:
Trigger filters = pull_request on main branch [OK]
- Assuming it runs on all pull requests
- Confusing push and pull_request triggers
- Thinking syntax is invalid when it is correct
Solution
Step 1: Check workflow file location
GitHub Actions requires workflow files to be inside the .github/workflows folder to detect and run them.Step 2: Evaluate other options
Copying Jenkinsfile syntax won't run but does not prevent detection; GitHub Actions works on private repos; file extension must be .yml or .yaml, but location is primary cause.Final Answer:
The workflow YAML file is not placed under the .github/workflows directory. -> Option DQuick Check:
Workflow location = .github/workflows folder [OK]
- Ignoring file location importance
- Assuming Jenkinsfile syntax works in GitHub Actions
- Thinking GitHub Actions only runs on public repos
Solution
Step 1: Understand Jenkins multi-OS testing
Jenkins pipelines can run parallel jobs on different OS agents to test across environments.Step 2: Use GitHub Actions matrix strategy
GitHub Actions supports a matrix strategy to run the same job on multiple OS runners like ubuntu-latest, windows-latest, and macos-latest automatically.Final Answer:
Use a matrix strategy in GitHub Actions to run jobs on ubuntu-latest, windows-latest, and macos-latest runners. -> Option CQuick Check:
Matrix strategy = multi-OS testing [OK]
- Trying to switch OS inside one runner
- Creating many manual workflows instead of matrix
- Believing GitHub Actions lacks multi-OS support
Ready to prove it?
Pass the test and this pattern moves unknown
