Skip to main content

Using conditions to control job execution

Prevent a job from running unless your conditions are met.

You can use the jobs.<job_id>.if conditional to prevent a job from running unless a condition is met. 您可以使用任何支持上下文和表达式来创建条件。 有关此键中支持哪些上下文的详细信息,请参阅“上下文参考”。

Example: Only run job for a specific repository

This example uses if to control when the production-deploy job can run. It will only run if the repository is named octo-repo-prod and is within the octo-org organization. Otherwise, the job will be marked as skipped.

YAML
name: example-workflow
on: [push]
jobs:
  production-deploy:
    if: github.repository == 'octo-org/octo-repo-prod'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '14'
      - run: npm install -g bats

Skipped jobs display the message "This check was skipped."

注意

A job that is skipped will report its status as "Success". It will not prevent a pull request from merging, even if it is a required check.