繁体   English   中英

从 Github 操作取消当前正在运行的工作流程

[英]Cancel current running workflow from Github Actions

我希望能够根据条件取消我当前运行的workflow

我试着像这样使用 这个动作

      - name: cancel workflow if none of files we look for changes has not changed
        if: steps.changed-files.outputs.any_changed != 'true'
        uses: styfle/cancel-workflow-action@0.10.0
        with:
          workflow_id: ${{ github.workflow_id }}
          access_token: ${{ github.token }}

但从日志中可以看出:

Found token: yes
Found workflow_id: ["12345567"]
Found 3 runs total.
Found 0 runs to cancel.

它只会取消其他同时运行的工作流。

有没有简单的方法解决这个问题,还是我应该求助于 GH API?

编辑:我已经在应该取消工作流的 rest 的步骤中尝试了这个

 gh api --method POST -H "Accept: application/vnd.github+json" https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel

但是它只返回一个{}并继续执行......

这是 go 关于它的一种方法

      - name: cancel run if none of files we look for changes has changed
        if: steps.changed-files.outputs.any_changed != 'true'
        uses: andymckay/cancel-action@0.2

      # needed since the run is not cancelled immediately
      - name: wait for run cancellation
        if: steps.changed-files.outputs.any_changed != 'true'
        shell: bash
        run: while true; do echo "Waiting for job to be cancelled"; sleep 5; done

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM