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.
How to Skip a Job in GitHub Actions ?
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.