How to Skip a Job in GitHub Actions ?
Last Updated :
16 Apr, 2024
With the help of GitHub Actions, developers can effectively automate a range of processes and workflows right within their repositories. You can develop, test, and publish your code using GitHub Actions without ever leaving the GitHub website. It provides an adaptable and configurable workflow framework using YAML file definitions that lets you set up events like pull requests, code pushes, and issue comments to cause actions to be triggered. Developers may increase collaboration, expedite product delivery, and streamline their development processes by utilizing GitHub Actions. This is the entire process for using the condition to skip the task.
What Are Github Actions?
GitHub Actions is a feature on the GitHub platform that helps automate tasks related to software development. With GitHub Actions, you can create workflows that automatically run actions whenever certain events occur in your GitHub repository. These events could include things like pushing code changes, opening pull requests, or merging branches. For example, you can set up a workflow that runs tests on your code whenever you push new changes, or automatically deploys your application to a hosting service when you Git merge a pull request. GitHub Actions makes it easier to automate repetitive tasks in your development workflow, saving you time and effort.
How To Skip A Job in GitHub Actions: A Step-By-Step Guide
Step 1: Create a Repository on GitHub for reference following this Article - Create a repository on GitHub.
Step 2: Here is a repository by the name of Skip. We need to create the YAML file under the workflow named blank.yml

- This is my sample blank.yaml under the workflows.
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
test:
runs-on: ubuntu-latest
if: false # This condition ensures the job is never executed
steps:
- name: Skip this job
run: echo "This job is skipped"
Here,
- Name: Defines the name of the workflow, which appears in the Actions tab of the repository.
- On: Specifies the events that trigger the workflow. In this case, the workflow runs on push events to the main branch, pull requests targeting the main branch, and manually triggered workflow dispatch events.
- Jobs: Contains one or more jobs that make up the workflow. Each job runs independently and can consist of multiple steps.
- Build Job: This workflow contains a single job named "build". It runs on an Ubuntu virtual machine (runner) specified by
runs-on: ubuntu-latest
. - Steps: Represents a sequence of tasks to be executed in the job. The steps include:
Checking out the repository using actions/checkout@v3
. Running a one-line script to print "Hello, world!". Running a multi-line script to demonstrate running multiple commands.
- Test Job: This job is defined but is set to never execute due to the
if: false
condition. It serves as an example of how to skip a job in a workflow.
Step 3: Click on Actions and click on CI.

Step 4: Here are the two jobs are running the file one is duild and test. Refer this screenshot the tet job was skipped. On pipeline I have mentioned "if: false"

Step 5: Here is the successfully completed job that is build job all are completed successfully.

Step 6: Here is the clear screenshot to for skipped the test job after licking the test job.

Job Declaration And Execution In GitHub Actions
- Job Declaration: In a GitHub Actions workflow file (typically
workflow.yml
), you define one or more jobs under the jobs
section. Each job represents a series of tasks that should be executed as part of the workflow. - Job Configuration: Each job is configured with properties like
name
, runs-on
, and steps
. The name
property provides a descriptive name for the job, runs-on
specifies the type of runner environment for the job (e.g., Ubuntu, macOS, Windows), and steps
define the sequence of tasks to be executed. - Steps: Within each job, you define a series of steps. Each step represents a single task or action to be performed, such as checking out the repository, running a script, or deploying an application.
- Execution: When a workflow is triggered (e.g., by a push event or a scheduled run), GitHub Actions automatically starts executing the defined jobs. Jobs can run sequentially or in parallel, depending on your workflow configuration.
Using Conditions ( if
) To control Job Execution
- Define Condition: In your workflow file, you can add an
if
statement to a job to specify the condition under which the job should run. - Condition Syntax: The condition can be any expression that evaluates to true or false. If the condition evaluates to true, the job will run. If it evaluates to false, the job will be skipped.
- Usage Examples:
- Skip a job based on a specific branch:
if: github.ref != 'refs/heads/main'
- Run a job only for pull requests:
if: github.event_name == 'pull_request'
- Execute a job only for specific events:
if: github.event_name == 'push' || github.event_name == 'pull_request'
Similar Reads
How to Run Python Script in GitHub Actions ? A tool available on GitHub that can help you automate chores in your software projects is called GitHub Actions. It enables you to design workflows that, when executed automatically, carry out actions like as deploying, testing, and even sending out notifications. It basically works like a small rob
6 min read
How to Run Bash Script in Github Actions ? GitHub Actions are helpful resources for coding. They automate processes in your GitHub projects, save you time and effort. It is possible that GitHub Actions will automate the steps involved in testing, deploying, and alerting users of your code. Because you can configure them to run at specified t
5 min read
How to use AWS CLI in GitHub Actions ? Through a command-line interface, Amazon offers a powerful tool called the Amazon Web Services Command Line Interface, or AWS CLI, which makes managing AWS resources easier. The importance of this is that it can simplify the process of utilizing AWS services straight from the terminal, removing the
4 min read
How to Add GitHub Actions Secrets ? When it comes to safely managing sensitive data in your workflowsâlike access tokens, API keys, and other credentialsâGitHub Actions secrets are essential. By using these tricks, you can securely access and save private information without exposing it to the source code of your repository. You may i
5 min read
How to get Build Number in GitHub Actions ? GitHub Actions is a powerful automation tool provided by GitHub, designed to streamline workflows and enhance collaboration among developers. It plays a vital role in CI/CD pipelines by automating tasks such as testing, building, and deploying software projects. With GitHub Actions, developers can d
5 min read