0
0
Jenkinsdevops~10 mins

Jenkins to GitHub Actions path - Commands & Configuration

Choose your learning style9 modes available
Introduction
Moving from Jenkins to GitHub Actions helps teams use built-in GitHub automation without managing separate servers. It solves the problem of maintaining Jenkins infrastructure by using cloud-hosted workflows integrated with your code repository.
When you want to automate testing and deployment directly from your GitHub repository without extra servers
When your Jenkins server is hard to maintain or update and you want a simpler cloud solution
When you want to use GitHub's marketplace of ready-made actions to speed up your pipeline setup
When you want to trigger workflows on GitHub events like pull requests or pushes automatically
When you want to reduce costs by using GitHub's free tier for CI/CD instead of running Jenkins agents
Config File - ci.yml
ci.yml
name: CI Pipeline

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up JDK 11
        uses: actions/setup-java@v3
        with:
          java-version: '11'
          distribution: 'temurin'

      - name: Build with Maven
        run: mvn clean install

      - name: Run tests
        run: mvn test

This GitHub Actions workflow named CI Pipeline runs on pushes and pull requests to the main branch.

The build job runs on a fresh Ubuntu machine.

Steps include checking out the code, setting up Java 11, building with Maven, and running tests.

Commands
Clone your GitHub repository locally to add the GitHub Actions workflow file.
Terminal
git clone https://github.com/example-user/example-repo.git
Expected OutputExpected
Cloning into 'example-repo'... remote: Enumerating objects: 10, done. remote: Counting objects: 100% (10/10), done. remote: Compressing objects: 100% (7/7), done. remote: Total 10 (delta 1), reused 10 (delta 1), pack-reused 0 Receiving objects: 100% (10/10), done. Resolving deltas: 100% (1/1), done.
Create the workflows directory and copy the GitHub Actions workflow file into the repository folder.
Terminal
mkdir -p example-repo/.github/workflows && cp ci.yml example-repo/.github/workflows/ci.yml
Expected OutputExpected
No output (command runs silently)
Add the workflow file to git, commit with a message, and push to the main branch to trigger the workflow.
Terminal
cd example-repo && git add .github/workflows/ci.yml && git commit -m "Add GitHub Actions CI workflow" && git push origin main
Expected OutputExpected
[main abc1234] Add GitHub Actions CI workflow 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/ci.yml Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 500 bytes | 500.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/example-user/example-repo.git def5678..abc1234 main -> main
Check the status of recent GitHub Actions workflow runs using GitHub CLI.
Terminal
gh run list --repo example-user/example-repo
Expected OutputExpected
Workflow runs for example-user/example-repo ID NAME STATUS CONCLUSION EVENT BRANCH AGE 123456 CI Pipeline completed success push main 2m ago
--repo - Specify the repository to check workflow runs
Key Concept

If you remember nothing else from this path, remember: GitHub Actions workflows live inside your repo and run automatically on GitHub events, replacing Jenkins server jobs.

Common Mistakes
Not placing the workflow file in the correct .github/workflows directory
GitHub Actions only detects workflows inside the .github/workflows folder, so the workflow won't run if misplaced.
Always put your YAML workflow files inside the .github/workflows directory at the root of your repository.
Pushing workflow changes to a branch other than the one configured in the workflow triggers
The workflow triggers only run on specified branches like main, so pushing to other branches won't start the workflow.
Ensure your workflow triggers include the branches you push to, or push to the configured branches like main.
Forgetting to commit and push the workflow file after creating it locally
GitHub Actions workflows run only after the workflow file is pushed to the repository.
After adding or editing workflow files, commit and push them to the remote repository to activate the workflows.
Summary
Create a GitHub Actions workflow YAML file inside .github/workflows to define your CI/CD pipeline.
Push the workflow file to your repository to trigger automated runs on events like push or pull request.
Use GitHub CLI or the GitHub web interface to monitor workflow run status and results.