Skip to main content

Using jobs in a workflow

Use workflows to run multiple jobs.

Overview

A workflow run is made up of one or morejobs,which run in parallel by default. To run jobs sequentially, you can define dependencies on other jobs using thejobs.<job_id>.needskeyword.

Each job runs in a runner environment specified byruns-on.

You can run an unlimited number of jobs as long as you are within the workflow usage limits. For more information, see "Usage limits, billing, and administration"for GitHub-hosted runners and"About self-hosted runners"for self-hosted runner usage limits.

If you need to find the unique identifier of a job running in a workflow run, you can use the GitHub API. For more information, see "REST API endpoints for GitHub Actions."

Setting an ID for a job

Usejobs.<job_id>to give your job a unique identifier. The keyjob_idis a string and its value is a map of the job's configuration data. You must replace<job_id>with a string that is unique to thejobsobject. The<job_id>must start with a letter or_and contain only Alpha numeric characters,-,or_.

Example: Creating jobs

In this example, two jobs have been created, and theirjob_idvalues aremy_first_jobandmy_second_job.

jobs:
my_first_job:
name:Myfirstjob
my_second_job:
name:Mysecondjob

Setting a name for a job

Usejobs.<job_id>.nameto set a name for the job, which is displayed in the GitHub UI.

Defining prerequisite jobs

Usejobs.<job_id>.needsto identify any jobs that must complete successfully before this job will run. It can be a string or array of strings. If a job fails or is skipped, all jobs that need it are skipped unless the jobs use a conditional expression that causes the job to continue. If a run contains a series of jobs that need each other, a failure or skip applies to all jobs in the dependency chain from the point of failure or skip onwards. If you would like a job to run even if a job it is dependent on did not succeed, use thealways()conditional expression injobs.<job_id>.if.

Example: Requiring successful dependent jobs

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

In this example,job1must complete successfully beforejob2begins, andjob3waits for bothjob1andjob2to complete.

The jobs in this example run sequentially:

  1. job1
  2. job2
  3. job3

Example: Not requiring successful dependent jobs

jobs:
job1:
job2:
needs:job1
job3:
if:${{always()}}
needs:[job1,job2]

In this example,job3uses thealways()conditional expression so that it always runs afterjob1andjob2have completed, regardless of whether they were successful. For more information, see "Evaluate expressions in workflows and actions."