我有以下工作:
jobs:
build:
name: Build
runs-on: [ self-hosted, linux ]
steps:
- uses: actions/checkout@v2
- name: Build
run: dotnet build
unit-test:
name: Unit test
if: github.event_name != 'release'
runs-on: [ self-hosted, linux ]
needs: build
steps:
- uses: actions/checkout@v2
- name: Run tests
run: dotnet test
publish:
name: Publish artifacts.zip
runs-on: [ self-hosted, linux ]
needs: unit-test
steps:
- uses: actions/checkout@v2
- run: dotnet publish
- name: Create artifact
run: |
mkdir -p ./code我不想在发行版上运行单元测试,但我仍然需要发布才能在构建后运行,而且我也想不出如何做到这一点。
我想将发布作业更改为: if github.event_name != 'release',然后needs: build,否则就像现在的needs: unit-test一样。在这种情况下,如何定义条件?
发布于 2022-11-03 11:09:09
我认为您可以通过将条件设置在步骤级别而不是在工作级别来实现您想要的结果。这样,即使没有运行任何步骤,GHA也会将作业视为run。如果由于没有运行任何步骤而没有将作业视为运行,则可以添加一个虚拟步骤(例如。- run: echo "Done!"),这将始终被运行。
jobs:
build:
name: Build
runs-on: [ self-hosted, linux ]
steps:
- uses: actions/checkout@v2
- name: Build
run: dotnet build
unit-test:
name: Unit test
runs-on: [ self-hosted, linux ]
needs: build
steps:
- uses: actions/checkout@v2
if: github.event_name != 'release'
- name: Run tests
run: dotnet test
if: github.event_name != 'release'
publish:
name: Publish artifacts.zip
runs-on: [ self-hosted, linux ]
needs: unit-test
steps:
- uses: actions/checkout@v2
- run: dotnet publish
- name: Create artifact
run: |
mkdir -p ./codehttps://stackoverflow.com/questions/72096859
复制相似问题