注: GitHub 托管的运行器目前在 GitHub Enterprise Server 上不受支持。 您可以在 GitHub 公共路线图 上查看有关未来支持计划的更多信息。
概览
You can use the jobs.<job_id>.if
conditional to prevent a job from running unless a condition is met. 您可以使用任何支持上下文和表达式来创建条件。
在 if
条件下使用表达式时,可以省略表达式语法 (${{ }}
),� 为 GitHub 会自动将 if
条件作为表达式求值。 For more information, see "Expressions."
Example: Only run job for 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.
name: example-workflow
on: [push]
jobs:
production-deploy:
if: github.repository == 'octo-org/octo-repo-prod'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
- run: npm install -g bats