Certified Jenkins Engineer

Backup and Configuration Management

Demo Migrating Jenkins Pipeline to GitHub Action

In this tutorial, you'll learn how to migrate existing Jenkins jobs into GitHub Actions workflows using the GitHub Actions Importer.

Prerequisites

  • A Jenkins account or organization with pipelines to migrate
  • A Jenkins personal API token with read or admin permissions
  • Docker installed (required by the importer)
  • GitHub CLI (gh) installed and authenticated

The image shows a GitHub documentation page about migrating from Jenkins to GitHub Actions using the GitHub Actions Importer. It includes prerequisites, limitations, and installation instructions for the CLI extension.

Limitations

Some features cannot be migrated automatically:

LimitationImpact
Scripted pipelinesNot supported—only declarative syntax
Secrets & unknown pluginsMust be recreated or handled manually

1. Install GitHub CLI & Importer Extension

On Ubuntu, add the GitHub CLI repository and install:

(type -p wget >/dev/null || (sudo apt update && sudo apt install wget -y)) \
  && sudo mkdir -p /etc/apt/keyrings \
  && wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg \
     | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg \
  && sudo chmod 644 /etc/apt/keyrings/githubcli-archive-keyring.gpg \
  && echo "deb [arch=$(dpkg --print-architecture) \
     signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] \
     https://cli.github.com/repos/github/cli/releases/apt/ \
     $(lsb_release -cs) main" \
     | sudo tee /etc/apt/sources.list.d/github-cli.list \
  && sudo apt update \
  && sudo apt install gh -y

Install the GitHub Actions Importer:

gh extension install github/gh-actions-importer
gh actions-importer -h

2. Authenticate with GitHub

Log in to GitHub via the CLI:

gh auth login

Follow the browser prompts to authorize.

The image shows a GitHub authorization page for the GitHub CLI, requesting access to a user's account and various organizations. There are options to cancel or authorize the application.


3. Configure Importer Credentials

You need two tokens:

  1. GitHub Personal Access Token (classic)

    • Scopes: repo, workflow
    • Create under Settings → Developer settings → Personal access tokens → Tokens (classic)

    The image shows a GitHub page for creating a new personal access token, with options to set a note, expiration date, and select scopes for the token.

  2. Jenkins API Token

    • Go to People → [your user] → Configure → API Token
    • Copy it before leaving the page

    The image shows a Jenkins dashboard with a list of build jobs, their statuses, last success and failure times, and durations. The interface includes navigation options on the left and user account details on the top right.

Run the configuration command and answer prompts:

gh actions-importer configure
  • Choose Jenkins
  • Enter your GitHub token & base URL (https://github.com)
  • Enter your Jenkins token, username & base URL (e.g. http://64.227.187.25:8080/)

4. Update the Importer

Keep the extension up to date:

gh actions-importer update

5. Audit & Forecast (Optional)

Review your Jenkins jobs before migration:

gh actions-importer audit jenkins --output-dir tmp/audit

Estimate GitHub Actions runner usage (requires a Jenkins plugin):

gh actions-importer forecast jenkins

The image shows a GitHub Docs page about migrating from Jenkins with GitHub Actions Importer, detailing steps for forecasting potential build runner usage. The page includes navigation links and a sidebar with related topics.


6. Dry Run a Jenkins Job

Locate your full Jenkins job URL:

The image shows a Jenkins dashboard displaying a list of jobs with their statuses, last success, last failure, and duration. The interface includes options for managing Jenkins, viewing job configurations, and build executor status.

Execute a dry-run to preview the workflow:

gh actions-importer dry-run jenkins \
  --source-url http://64.227.187.25:8080/job/Generate%20ASCII%20Artwork/ \
  --output-dir tmp/dry-run

Inspect the generated workflow YAML:

cat tmp/dry-run/Generate_ASCII_Artwork/.github/workflows/generate_ascii_artwork.yml
name: Generate_ASCII_Artwork
on:
  workflow_dispatch:
env:
  # TimestamperBuildWrapper was not converted
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v4
      - name: run command
        shell: bash
        run: |
          # Fetch a piece of advice
          curl -s https://api.adviceslip.com/advice > advice.json
          cat advice.json
          # Validate word count
          jq -r .slip.advice advice.json > advice.message
          [ $(wc -w < advice.message) -gt 5 ] \
            || (echo "Advice has 5 words or less" && exit 1)
          # Install cowsay and display
          sudo apt-get install cowsay -y
          export PATH="$PATH:/usr/games:/usr/local/games"
          cowsay -f "$(ls /usr/share/cowsay/cows | shuf -n 1)" \
            < advice.message

7. Migrate to GitHub Actions

Prepare your target repository (e.g., jenkins-to-actions):

The image shows a GitHub repository page titled "jenkins-to-actions" with an initial commit made 16 minutes ago. The repository is public and contains a README file.

Run the migration:

gh actions-importer migrate jenkins \
  --source-url http://64.227.187.25:8080/job/Generate%20ASCII%20Artwork/ \
  --target-url https://github.com/jenkins-kk-demo/jenkins-to-actions \
  --output-dir tmp/migrate

A pull request will be created automatically:

The image shows a GitHub pull request page titled "Convert Generate_ASCII_Artwork to GitHub Actions," with details about the commit and options to merge the pull request.

Merge the PR to land the workflow in .github/workflows/generate_ascii_artwork.yml:

cat .github/workflows/generate_ascii_artwork.yml
name: Generate_ASCII_Artwork
on:
  workflow_dispatch:
  push:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: run command
        shell: bash
        run: |
          curl -s https://api.adviceslip.com/advice > advice.json
          jq -r .slip.advice advice.json > advice.message
          [ $(wc -w < advice.message) -gt 5 ] \
            || (echo "Advice has 5 words or less" && exit 1)
          sudo apt-get install cowsay -y
          export PATH="$PATH:/usr/games:/usr/local/games"
          cowsay -f "$(ls /usr/share/cowsay/cows | shuf -n 1)" \
            < advice.message

8. Run the Workflow

Trigger the workflow manually or push to main:

The image shows a GitHub Actions interface with a workflow named "Generate_ASCII_Artwork" that has been manually run. The interface includes options for managing workflows and running them.

After completion, check the logs to see your ASCII artwork output.


Watch Video

Watch video content

Previous
Github Actions Basics