Jenkins에서 GitHub Actions로 마이그레이션하기

Jenkins에서 GitHub Actions로 마이그레이션하기

GitHub Actions와 Jenkins는 여러 유사점을 공유하기 때문에 GitHub Actions로의 마이그레이션이 비교적 간단할 수 있어요. 이 가이드에서는 두 시스템의 차이점과 Jenkins 파이프라인 구성을 GitHub Actions 워크플로우로 변환하는 방법을 알려드릴게요.

출처: 문서

본문

Introduction

Jenkins와 GitHub Actions는 모두 코드를 자동으로 빌드, 테스트, 게시, 릴리스, 배포하는 워크플로우를 만들 수 있게 해 줘요. Jenkins와 GitHub Actions는 워크플로우 구성에서 몇 가지 유사점을 공유해요.

  • Jenkins는 GitHub Actions 워크플로우 파일과 유사한 Declarative Pipelines로 워크플로우를 만들어요.
  • Jenkins는 stages를 사용해서 단계 모음을 실행하고, GitHub Actions는 job을 사용해서 하나 이상의 단계 또는 개별 명령을 그룹화해요.
  • Jenkins와 GitHub Actions는 컨테이너 기반 빌드를 지원해요. 자세한 내용은 Creating a Docker container action 문서를 참고하세요.
  • 단계나 작업은 재사용되고 커뮤니티와 공유될 수 있어요.

자세한 내용은 Understanding GitHub Actions 문서를 참고하세요.

Key differences

  • Jenkins에는 파이프라인을 만드는 두 가지 문법 유형이 있어요: Declarative Pipeline과 Scripted Pipeline. GitHub Actions는 YAML을 사용해서 워크플로우와 구성 파일을 만들어요. 자세한 내용은 Workflow syntax for GitHub Actions 문서를 참고하세요.
  • Jenkins 배포는 일반적으로 자체 호스팅 방식이며, 사용자가 자체 데이터 센터에서 서버를 유지 관리해요. GitHub Actions는 job을 실행하는 데 사용할 수 있는 자체 러너를 호스팅하면서 자체 호스팅 러너도 지원하는 하이브리드 클라우드 접근 방식을 제공해요. 자세한 내용은 Self-hosted runners 문서를 참고하세요.

Comparing capabilities

Distributing your builds

Jenkins는 빌드를 단일 빌드 에이전트로 보내거나 여러 에이전트에 분산할 수 있어요. 또한 운영 체제 유형 같은 다양한 속성에 따라 에이전트를 분류할 수 있어요.

마찬가지로 GitHub Actions는 job을 GitHub 호스팅 또는 자체 호스팅 러너로 보낼 수 있고, 레이블을 사용해서 다양한 속성에 따라 러너를 분류할 수 있어요. 자세한 내용은 Understanding GitHub ActionsSelf-hosted runners 문서를 참고하세요.

Using sections to organize pipelines

Jenkins는 Declarative Pipelines를 여러 섹션으로 나눠요. 마찬가지로 GitHub Actions는 워크플로우를 별도의 섹션으로 구성해요. 아래 표는 Jenkins 섹션과 GitHub Actions 워크플로우를 비교한 것입니다.

Jenkins Directives GitHub Actions
agent jobs.<job_id>.runs-on
jobs.<job_id>.container
post None
stages jobs
steps jobs.<job_id>.steps

Using directives

Jenkins는 Declarative Pipelines를 관리하기 위해 지시문(directives)을 사용해요. 이러한 지시문은 워크플로우의 특성과 실행 방식을 정의해요. 아래 표는 이러한 지시문이 GitHub Actions의 개념에 어떻게 매핑되는지 보여줍니다.

Jenkins Directives GitHub Actions
environment jobs.<job_id>.env
jobs.<job_id>.steps[*].env
options jobs.<job_id>.strategy
jobs.<job_id>.strategy.fail-fast
jobs.<job_id>.timeout-minutes
parameters inputs
outputs
triggers on
on.<event_name>.types
on.\.\<branches|tags>
on.\<pull\_request>.\
on.\<push|pull\_request>.paths
triggers { upstreamprojects() } jobs.<job_id>.needs
Jenkins cron syntax on.schedule
stage jobs.<job_id>
jobs.<job_id>.name
tools Specifications for GitHub-hosted runners
input inputs
when jobs.<job_id>.if

Using sequential stages

Parallel job processing

Jenkins는 stagessteps를 병렬로 실행할 수 있어요. GitHub Actions는 job을 병렬로 실행하고, 단계 수준 문법을 사용해서 job 내에서 단계를 동시에 실행할 수도 있어요. 자세한 내용은 Workflow syntax for GitHub Actions 문서를 참고하세요.

Jenkins Parallel GitHub Actions
parallel jobs.<job_id>.strategy.max-parallel

Matrix

GitHub Actions와 Jenkins 모두 매트릭스를 사용해서 다양한 시스템 조합을 정의할 수 있어요.

Jenkins GitHub Actions
axis strategy/matrix
context
stages steps-context
excludes None

Using steps to execute tasks

Jenkins는 stepsstages로 그룹화해요. 이 각 단계는 스크립트, 함수, 명령 등이 될 수 있어요. 마찬가지로 GitHub Actions는 jobs를 사용해서 특정 steps 그룹을 실행해요.

Jenkins GitHub Actions
steps jobs.<job_id>.steps

Examples of common tasks

Scheduling a pipeline to run with cron

Jenkins pipeline with cron

pipeline {
  agent any
  triggers {
    cron('H/15 * * * 1-5')
  }
}

GitHub Actions workflow with cron

on:
  schedule:
    - cron: '*/15 * * * 1-5'

schedule 이벤트와 허용된 cron 문법에 대한 자세한 내용은 Events that trigger workflows 문서를 참고하세요.

Configuring environment variables in a pipeline

Jenkins pipeline with an environment variable

pipeline {
  agent any
  environment {
    MAVEN_PATH = '/usr/local/maven'
  }
}

GitHub Actions workflow with an environment variable

jobs:
  maven-build:
    env:
      MAVEN_PATH: '/usr/local/maven'

Building from upstream projects

Jenkins pipeline that builds from an upstream project

pipeline {
  triggers {
    upstream(
      upstreamProjects: 'job1,job2',
      threshold: hudson.model.Result.SUCCESS
    )
  }
}

GitHub Actions workflow that builds from an upstream project

jobs:
  job1:
  job2:
    needs: job1
  job3:
    needs: [job1, job2]

Building with multiple operating systems

Jenkins pipeline that builds with multiple operating systems

pipeline {
  agent none
  stages {
    stage('Run Tests') {
      matrix {
        axes {
          axis {
            name: 'PLATFORM'
            values: 'macos', 'linux'
          }
        }
        agent { label "${PLATFORM}" }
        stages {
          stage('test') {
            tools { nodejs "node-20" }
            steps {
              dir("scripts/myapp") {
                sh(script: "npm install -g bats")
                sh(script: "bats tests")
              }
            }
          }
        }
      }
    }
  }
}

GitHub Actions workflow that builds with multiple operating systems

name: demo-workflow
on:
  push:
jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [macos-latest, ubuntu-latest]
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v7
        with:
          node-version: 20
      - run: npm install -g bats
      - run: bats tests
        working-directory: ./scripts/myapp

더 알아보기 (Learn more)