skip to Main Content

I have a Github repository (repo A) with a workflow running inside that repo (working with Terraform file and applying them on AWS). I am trying to trigger that workflow from a different Github repository (repo B), so I created a workflow in repo B, made a checkout to repo A and then tried to trigger the workflow with "gh" CLI.

jobs:
  traffic-split:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read
    steps:
    - name: Checkout to repo A
      uses: actions/checkout@master
      with:
        repository: <My_Organization>/<My_Called_Repo>
        token: ${{ secrets.GH_TOKEN }}

    - name: Run Workflow
      run: |
        curl -X POST -H "Content-Type: application/json" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/<My_Organization>/<My_Called_Repo>/.github/workflows/<My_Called_Worflow>/dispatches"

However, it fails with 404 NOT FOUND.

{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event"
}

When running other GH CLI commands like "gh workflow list", etc. it works, but triggering a workflow fails. What am I missing when triggering the workflow?

Thank you!

2

Answers


  1. Try using GitHub action:
    workflow-dispatch

      - name: Invoke Server Workflow 
        uses: benc-uk/workflow-dispatch@v1
        with:
          workflow: Server build
          repo: some_repo
          token: ${{ secrets.PAT_TOKEN }}
          ref: refs/heads/main
    
    Login or Signup to reply.
  2. Try using GitHub API Docs:
    GitHub API

    - name: Run Workflow
      run: |
        $uri 
        ('https://api.github.com/repos/{0}/{1}/actions/workflows/{2}/dispatches' 
        -f $(ORGANIZATION), $(REPOSITORY), $(WORKFLOW_NUMBER))
        $Body = @{'ref' = 'main'} | ConvertTo-Json
        $params = @{ContentType='application/json'
        Headers     = @{'authorization'="token $(GITHUB_TOKEN)"
        'accept'='application/vnd.github.everest-preview+json'}
        Method='Post'
        URI=$Uri
        Body=$Body
        }
        Invoke-RestMethod @params -verbose
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search