将 Github Actions 用于某些 CI/CD。
目前,我遇到了奇怪的行为,尽管满足了条件,但我的工作却被跳过了。 deploy-api
有两个条件,如果代码被推送到 master 和 test-api
是成功的。但即使我们满足这些条件,它仍然被跳过。
jobs:
test-api:
name: Run tests on API
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Get dependencies
run: npm install
working-directory: ./api
- name: Run tests
run: npm run test
working-directory: ./api
deploy-api:
needs: test-api # other job must finish
if: github.ref == 'refs/heads/master' && needs.test-api.status == 'success' #only run if it's a commit to master AND previous success
如图所示,尽管推送是在主分支上(如顶部所示)并且前一个工作成功,但第二个工作被跳过。
我在代码中遗漏了什么吗?有谁知道可以使用的解决方法?
如果 UI 告诉用户它被跳过的原因,那就太好了!
最佳答案
使用 needs.test-api.result == 'success'
(没有 .status
)在 if
中表达。
见 https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#needs-context .
关于Github Actions 作业被跳过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66129469/