提问人:Ashar 提问时间:7/24/2023 更新时间:7/25/2023 访问量:109
如何执行需要在 github 操作中跳过的作业的作业
How to execute a job that needs a job that was skipped in github actions
问:
下面的工作流有 4 个作业。
我希望作业被执行,无论它所依赖的作业是否被跳过,即 和。conditional-job
skip-job
build
请让我知道这是否以及如何可能。
name: My GitHub Actions Workflow
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: This job runs only on pull requests
run: echo "JOB name build"
deploy:
if: ${{ false }}
runs-on: ubuntu-latest
steps:
- name: This job runs only on pull requests
run: echo "JOB name deploy"
# Your deployment steps go here...
skip-job:
if: ${{ false }} # This job will never run
runs-on: ubuntu-latest
steps:
- name: This job is skipped
run: echo "This job won't run because the if condition is set to false"
conditional-job:
needs:
- skip-job # This sets the 'skip-job' job as a dependency
- deploy # This sets the 'deploy' job as a dependency
if: ${{ true }}
runs-on: ubuntu-latest
steps:
- name: This job runs only on pull requests
run: echo "JOB name conditional-job"
请告诉我。
答:
0赞
Krzysztof Madej
7/25/2023
#1
请使用表达式needs.skip-job.result == 'skipped' || needs. deploy.result == 'skipped'
如果不确定结果值,可以在添加条件之前打印出来
conditional-job:
needs:
- skip-job # This sets the 'skip-job' job as a dependency
- deploy # This sets the 'deploy' job as a dependency
if: ${{ true }}
runs-on: ubuntu-latest
steps:
- name: This job runs only on pull requests
run: echo "JOB name conditional-job"
- name: check result
run: |
echo 'needs.skip-job.result'
echo 'needs.deploy.result'
评论