Cross-repository and workflow to trigger workflow dispatch

Jane
Nov 11, 2021

最近在Github enterprise上做了跨repo的workflow trigger

目前使用的是v3版本的API

可以參照這邊<---

要先在Github拿自己的Personal Access Token(PAT)

並且把PAT設定在Github的secrets中

這樣API才能跟Github做Auth

依照文件上的做法打POST給github v3的API

主要改的地方是

  • https

要依照自己的repo設定

https://${git-host-name}/api/v3/repos/${owner}/${repo-name}/actions/workflows/${workflow-file-name}/dispatches
  • ref

可以是branch, tag, or commit SHA

-d '{"ref": "${branch or tag name}"}'

其他的就跟以下code line一樣


name: repository-dispatch
on: push:jobs: repository-dispatch-job: runs-on: self-hosted steps: - name: POC - Dispatch workflow at same repository run: | curl -X POST \ -H "accept: application/vnd.github.v3+json" \ https://${git-host-name}/api/v3/repos/${owner}/${repo-name}/actions/workflows/${workflow-file-name}/dispatches \ -u ${{ secrets.PAT_TOKEN }} \ -d '{"ref": "master"}' - name: POC - Dispatch workflow at another repository run: | curl -X POST \ -H "accept: application/vnd.github.v3+json" \ https://${git-host-name}/api/v3/repos/${owner}/${repo-name}/actions/workflows/${workflow-file-name}/dispatches\ -u ${{ secrets.PAT_TOKEN }} \ -d '{"ref": "${branch or tag name}"}'

--

--