Skip to content

Latest commit

 

History

History
229 lines (181 loc) · 11.7 KB

migrating-from-jenkins-to-github-actions.md

File metadata and controls

229 lines (181 loc) · 11.7 KB
titleintroredirect_fromversionstypetopicsshortTitle
Migrating from Jenkins to GitHub Actions
{% data variables.product.prodname_actions %} and Jenkins share multiple similarities, which makes migration to {% data variables.product.prodname_actions %} relatively straightforward.
/actions/learn-github-actions/migrating-from-jenkins-to-github-actions
/actions/migrating-to-github-actions/migrating-from-jenkins-to-github-actions
/actions/migrating-to-github-actions/manual-migrations/migrating-from-jenkins-to-github-actions
fptghesghec
*
*
*
tutorial
Jenkins
Migration
CI
CD
Migrate from Jenkins

{% data reusables.actions.enterprise-github-hosted-runners %}

Introduction

Jenkins and {% data variables.product.prodname_actions %} both allow you to create workflows that automatically build, test, publish, release, and deploy code. Jenkins and {% data variables.product.prodname_actions %} share some similarities in workflow configuration:

  • Jenkins creates workflows using Declarative Pipelines, which are similar to {% data variables.product.prodname_actions %} workflow files.
  • Jenkins uses stages to run a collection of steps, while {% data variables.product.prodname_actions %} uses jobs to group one or more steps or individual commands.
  • Jenkins and {% data variables.product.prodname_actions %} support container-based builds. For more information, see AUTOTITLE.
  • Steps or tasks can be reused and shared with the community.

For more information, see AUTOTITLE.

Key differences

  • Jenkins has two types of syntax for creating pipelines: Declarative Pipeline and Scripted Pipeline. {% data variables.product.prodname_actions %} uses YAML to create workflows and configuration files. For more information, see AUTOTITLE.
  • Jenkins deployments are typically self-hosted, with users maintaining the servers in their own data centers. {% data variables.product.prodname_actions %} offers a hybrid cloud approach by hosting its own runners that you can use to run jobs, while also supporting self-hosted runners. For more information, see AUTOTITLE.

Comparing capabilities

Distributing your builds

Jenkins lets you send builds to a single build agent, or you can distribute them across multiple agents. You can also classify these agents according to various attributes, such as operating system types.

Similarly, {% data variables.product.prodname_actions %} can send jobs to {% data variables.product.prodname_dotcom %}-hosted or self-hosted runners, and you can use labels to classify runners according to various attributes. For more information, see AUTOTITLE and AUTOTITLE.

Using sections to organize pipelines

Jenkins splits its Declarative Pipelines into multiple sections. Similarly, {% data variables.product.prodname_actions %} organizes its workflows into separate sections. The table below compares Jenkins sections with the {% data variables.product.prodname_actions %} workflow.

Jenkins Directives{% data variables.product.prodname_actions %}
agentjobs.<job_id>.runs-on
jobs.<job_id>.container
postNone
stagesjobs
stepsjobs.<job_id>.steps

Using directives

Jenkins uses directives to manage Declarative Pipelines. These directives define the characteristics of your workflow and how it will execute. The table below demonstrates how these directives map to concepts within {% data variables.product.prodname_actions %}.

Jenkins Directives{% data variables.product.prodname_actions %}
environmentjobs.<job_id>.env
jobs.<job_id>.steps[*].env
optionsjobs.<job_id>.strategy
jobs.<job_id>.strategy.fail-fast
jobs.<job_id>.timeout-minutes
parametersinputs
outputs
triggerson
on.<event_name>.types
on.<push>.<branches|tags>
on.<pull_request>.<branches>
on.<push|pull_request>.paths
triggers { upstreamprojects() }jobs.<job_id>.needs
Jenkins cron syntaxon.schedule
stagejobs.<job_id>
jobs.<job_id>.name
toolsSpecifications for {% data variables.product.prodname_dotcom %}-hosted runners
inputinputs
whenjobs.<job_id>.if

Using sequential stages

Parallel job processing

Jenkins can run the stages and steps in parallel, while {% data variables.product.prodname_actions %} currently only runs jobs in parallel.

Jenkins Parallel{% data variables.product.prodname_actions %}
paralleljobs.<job_id>.strategy.max-parallel

Matrix

Both {% data variables.product.prodname_actions %} and Jenkins let you use a matrix to define various system combinations.

Jenkins{% data variables.product.prodname_actions %}
axisstrategy/matrix
context
stagessteps-context
excludesNone

Using steps to execute tasks

Jenkins groups steps together in stages. Each of these steps can be a script, function, or command, among others. Similarly, {% data variables.product.prodname_actions %} uses jobs to execute specific groups of steps.

Jenkins{% data variables.product.prodname_actions %}
stepsjobs.<job_id>.steps

Examples of common tasks

Scheduling a pipeline to run with cron

Jenkins pipeline with cron

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

{% data variables.product.prodname_actions %} workflow with cron

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

Configuring environment variables in a pipeline

Jenkins pipeline with an environment variable

pipeline {agent anyenvironment {MAVEN_PATH = '/usr/local/maven'}}

{% data variables.product.prodname_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)}}

{% data variables.product.prodname_actions %} workflow that builds from an upstream project

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

Building with multiple operating systems

Jenkins pipeline that builds with multiple operating systems

pipeline {agent nonestages {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")}}}}}}}}

{% data variables.product.prodname_actions %} workflow that builds with multiple operating systems

name: demo-workflowon: push: jobs: test: runs-on: {% raw %}${{ matrix.os }}{% endraw %}strategy: fail-fast: falsematrix: os: [macos-latest, ubuntu-latest]steps: - uses: {% data reusables.actions.action-checkout %} - uses: {% data reusables.actions.action-setup-node %}with: node-version: 20 - run: npm install -g bats - run: bats testsworking-directory: ./scripts/myapp
close