📖 Scenario: You work in a team that uses Jenkins for continuous integration. Now, your team wants to move the build process to GitHub Actions for better integration with GitHub repositories.This project will guide you step-by-step to create a simple Jenkins pipeline and then translate it into a GitHub Actions workflow.
🎯 Goal: Build a Jenkins pipeline script that runs a simple build step, then create a GitHub Actions workflow file that performs the same build step.
📋 What You'll Learn
Create a Jenkins pipeline script with a build stage
Add a variable for the build command
Write a GitHub Actions workflow YAML file using the build command
Display the final GitHub Actions workflow content
💡 Why This Matters
🌍 Real World
Many teams migrate from Jenkins to GitHub Actions to simplify CI/CD and integrate better with GitHub repositories.
💼 Career
Understanding how to write Jenkins pipelines and GitHub Actions workflows is essential for DevOps engineers and developers working with CI/CD pipelines.
Progress0 / 4 steps
1
Create a Jenkins pipeline with a build stage
Write a Jenkins pipeline script named Jenkinsfile that has a pipeline block with an agent any and a stage called Build that runs the shell command echo Building project inside a steps block.
Jenkins
Hint
Use pipeline block with agent any. Inside stages, add a stage named 'Build'. Use steps to run sh 'echo Building project'.
2
Add a build command variable
Add a variable called buildCommand at the top of the Jenkinsfile and set it to echo Building project. Then update the sh step to use this variable instead of the hardcoded command.
Jenkins
Hint
Define def buildCommand = "echo Building project" before pipeline. Replace sh 'echo Building project' with sh buildCommand.
3
Create a GitHub Actions workflow using the build command
Create a GitHub Actions workflow YAML file named build.yml with a job called build that runs on ubuntu-latest. Use a step that runs the command stored in buildCommand variable from Jenkinsfile, which is echo Building project.
Jenkins
Hint
Start with name: Build and on: [push]. Define jobs.build.runs-on: ubuntu-latest. Add a step with run: echo Building project.
4
Display the GitHub Actions workflow content
Print the entire content of the GitHub Actions workflow YAML file as a string exactly as created in Step 3.
Jenkins
Hint
Use a print statement with triple quotes or escaped newlines to show the YAML content exactly.
Practice
(1/5)
1. What is the main difference between Jenkins and GitHub Actions in terms of where the automation configuration is stored?
easy
A. Both Jenkins and GitHub Actions store workflows only on external servers.
B. GitHub Actions stores workflow files inside the repository, Jenkins uses an external server.
C. Jenkins stores workflows inside the repository, GitHub Actions uses an external server.
D. Both Jenkins and GitHub Actions store workflows only inside the repository.
Solution
Step 1: Understand Jenkins workflow storage
Jenkins typically stores job configurations on its own server, separate from the code repository.
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 B
Quick Check:
Workflow location = repository for GitHub Actions [OK]
Hint: Remember: GitHub Actions config lives with your code [OK]
Common Mistakes:
Thinking Jenkins stores configs in the repo
Assuming GitHub Actions uses external servers only
Confusing storage locations for both tools
2. Which of the following is the correct syntax to trigger a GitHub Actions workflow on a push to the main branch?
easy
A. on: push: branches: [main]
B. trigger: push main
C. event: push branch main
D. when: push to main
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 A
Quick Check:
Trigger syntax = 'on:' keyword [OK]
Hint: GitHub Actions triggers start with 'on:' in YAML [OK]
Common Mistakes:
Using 'trigger' instead of 'on' keyword
Incorrect YAML indentation or keywords
Confusing event names and branch filters
3. Given this GitHub Actions workflow snippet, what will happen when a pull request is opened?
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..."
medium
A. The workflow runs only when a pull request targets the main branch.
B. The workflow runs on any pull request regardless of target branch.
C. The workflow runs only on push events, not pull requests.
D. The workflow will fail due to syntax errors.
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 A
Quick Check:
Trigger filters = pull_request on main branch [OK]
Hint: Check 'on:' and branch filters to predict workflow triggers [OK]
Common Mistakes:
Assuming it runs on all pull requests
Confusing push and pull_request triggers
Thinking syntax is invalid when it is correct
4. You migrated a Jenkins pipeline to GitHub Actions but the workflow does not run on push events. Which is the most likely cause?
medium
A. The workflow file is named with a .json extension instead of .yml.
B. The Jenkinsfile syntax was copied directly into the GitHub Actions YAML.
C. The repository is private and GitHub Actions only works on public repos.
D. The workflow YAML file is not placed under the .github/workflows directory.
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 D
Quick Check:
Workflow location = .github/workflows folder [OK]
Hint: Put workflow files in .github/workflows folder [OK]
Common Mistakes:
Ignoring file location importance
Assuming Jenkinsfile syntax works in GitHub Actions
Thinking GitHub Actions only runs on public repos
5. You want to convert a Jenkins pipeline that runs tests on multiple operating systems into a GitHub Actions workflow. Which approach correctly replicates this behavior?
hard
A. Create separate workflows for each OS and trigger them manually.
B. Use a single job with a shell script that switches OS environments inside the runner.
C. Use a matrix strategy in GitHub Actions to run jobs on ubuntu-latest, windows-latest, and macos-latest runners.
D. GitHub Actions does not support multiple OS testing; use Jenkins instead.
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 C
Quick Check:
Matrix strategy = multi-OS testing [OK]
Hint: Use matrix to test multiple OS in one workflow [OK]
Common Mistakes:
Trying to switch OS inside one runner
Creating many manual workflows instead of matrix
Believing GitHub Actions lacks multi-OS support
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.