Continuous Integration and Continuous Delivery (CI/CD) pipelines have revolutionized the Software Development Life Cycle (SDLC) by automating the building, testing, and actual deployment of your infrastructure and applications.
Jenkins is one of the oldest and most widely utilized CI/CD tools, whereas GitHub Actions simplifies CI/CD by allowing developers to create workflows natively within GitHub.
What is Jenkins?
Jenkins is a self-hosted CI/CD platform that is highly customizable and extendable. It allows users to automate different tasks from the SDLC. Due to its vast ecosystem of plugins, Jenkins is adaptable to different workloads and environments.
Key features:
- Open-source - Jenkins is open-source and has a rich ecosystem of plugins
- Declare pipeline as Code - With Jenkins, you can use the DSL language to define your pipelines as code
- Integrates with many programming languages - You can build pipelines for anything you can imagine
- Distributed builds - Jenkins gives you the ability to distribute workloads across multiple servers
How to use Jenkins?
Jenkins can be installed on any VM, or you can even install it on your Kubernetes cluster.
To show you an example, we will install it on an existing K8s cluster using Helm:
helm repo add jenkins https://charts.jenkins.io
helm repo update
The above commands will add the Jenkins Helm charts inside my environment. Next, I will create a namespace for Jenkins:
kubectl create namespace jenkins
To install Jenkins on the K8s cluster you can run:
helm install jenkins jenkins/jenkins --namespace jenkins
We will need to get the initial admin password for it:
kubectl exec --namespace jenkins -it svc/jenkins -c jenkins -- /bin/cat /run/secrets/additional/chart-admin-password && echo
To access Jenkins locally, we will need to do port forwarding (you can also define an ingress if you would like to access it):
kubectl --namespace jenkins port-forward svc/jenkins 8080:8080
Then, go to your browser and navigate to localhost:8080.
After logging in, you can set up a pipeline by going to the Dashboard and selecting a new item.
Example Jenkins pipeline that runs your Terraform workflow:
pipeline {
agent any
environment {
TF_IN_AUTOMATION = 'true'
AWS_CREDENTIALS = credentials('aws-credentials')
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Terraform Init') {
steps {
sh 'terraform init'
}
}
stage('Terraform Plan') {
steps {
sh 'terraform plan -out=tfplan'
}
}
stage('Approval') {
steps {
input message: 'Do you want to apply this plan?', ok: 'Apply'
}
}
stage('Terraform Apply') {
steps {
sh 'terraform apply -auto-approve tfplan'
}
}
}
post {
always {
cleanWs()
}
}
}
Read more: Terraform with Jenkins Tutorial -- How to Manage Workflows
What is GitHub Actions?
GitHub Actions is a CI/CD platform that automates your SDLC processes. It allows you to build, test, and deploy infrastructure and applications directly from your GitHub repository by creating custom workflows. It offers various configuration options for triggers based on commits and merges, and it is highly extensible with its actions marketplace.
You can create and publish the actions you want to contribute and make other people's lives easier.
Key features:
- Native CI/CD integration with your GitHub repositories
- Event-driven - Pipelines and steps inside the pipelines can run based on various events
- Built-in marketplace - GitHub Actions has a rich marketplace of reusable actions that you can use inside your workflows
- Self-hosted runners - GitHub Actions gives you the ability to use your own runners for building and running your workflows
How to use GitHub Actions?
You can use GitHub Actions by simply creating a .github/worfklows directory in your repository. In this workflows directory, you can define as many yaml files as you want, and each of these files will correspond to a pipeline.
Example GitHub Actions pipeline that runs your Terraform workflow:
name: "Terraform pipeline"
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
env:
TF_IN_AUTOMATION: true
jobs:
terraform:
name: "Terraform"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Terraform Init
run: terraform init
- name: Terraform Format
run: terraform fmt -check
- name: Terraform Plan
run: terraform plan -out=tfplan
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: terraform apply -auto-approve tfplan
Read more: How to Manage & Scale Terraform with GitHub Actions
💡 You might also like:
- What is Developer Self-Service? Model, Benefits & Examples
- Strategies & Best Practices for Building a Scalable Infrastructure
- DevOps Maturity Model : Levels, Metrics & Benefits
GitHub Actions and Jenkins similarities
Both GitHub Actions and Jenkins are powerful CI/CD tools that allow engineers to automate the SDLC process. They offer extensive customization options - GitHub actions using its marketplace, while Jenkins relies on a powerful plugin ecosystem.
With both of these tools you can automate the deployment of your applications independent of the programming language used, and you can also automate your infrastructure workflows (this can be cumbersome in both cases).
GitHub Actions and Jenkins allow you to use your own infrastructure for running jobs with self-hosted runners and provide ways to store and use secrets.
The differences between GitHub Actions and Jenkins
GitHub Actions can be used both self-hosted and as a SaaS, whereas Jenkins is self-hosted only. Pipelines are defined using different languages - GitHub Actions relies on YAML, while Jenkins uses Groovy.
Jenkins requires more time to master due to its greater complexity and customization options, while GitHub Actions' learning curve is gentler. Their cost structure is different. Jenkins being open-source means that you will have to pay only for the infrastructure that hosts Jenkins, whereas, in GitHub Actions' case, you get a free tier with usage-based pricing beyond that.
Is GitHub Actions better than Jenkins?
GitHub Actions is newer than Jenkins and has many reusable actions that you can leverage for building your pipelines. However, if you are not using GitHub for your VCS, GitHub Actions doesn't make too much sense. Jenkins is more versatile on this point, and it can be used with any VCS. It is highly extendable with plugins but lacks a SaaS version.
There is no right or wrong between making a choice between these two, but it should always depend on what tooling you are using, and if you want to maintain a self-hosted tool for your tooling.
Alternative to GitHub Actions and Jenkins - Spacelift
When it comes to infrastructure orchestration, it's becoming clearer that generic CI/CD platforms such as GitHub Actions and Jenkins are not specialized enough to take care of everything you might need in your workflows. That's where Spacelift shines.
With Spacelift, you get:
- Policies to control what kind of resources engineers can create, what parameters they can have, how many approvals you need for a run, what kind of task you execute, what happens when a pull request is open, and where to send your notifications
- Stack dependencies to build multi-infrastructure automation workflows with dependencies, having the ability to build a workflow that, for example, generates your ec2 instances using Terraform and combines it with Ansible to configure them
- Self-service infrastructure via Blueprints, or Spacelift's Kubernetes operator, enabling your developers to do what matters -- developing application code while not sacrificing control
- Creature comforts such as contexts (reusable containers for your environment variables, files, and hooks), and the ability to run arbitrary code
- Drift detection and optional remediation
If you want to learn more about what you can do with Spacelift, check out this article.
Key points
GitHub Actions and Jenkins are both great choices for managing the CI/CD processes across your application deployment, but generally, they struggle when it comes to infrastructure, especially because you have to build many mechanisms to obtain a decent workflow.
If you are interested in a product that can orchestrate provisioning, configuration, and governance, across your infrastructure, Spacelift is the answer. Create a free account with Spacelift today, or book a demo with one of our engineers.
Written by Flavius Dinu