is there a way to get workflow id while running gh action

Viewed 1567

I'm generating workflow logs in this format while running GitHub action

${{ github.workflow }}-${{ github.run_id }}-${{ github.run_number }}.log

I want to get the workflow id which we see in the rest call

"workflow_runs": [
    {
      "id": 30433642,
       "name": "Build",
    }
  ]

checked here: https://docs.github.com/en/actions/learn-github-actions/contexts#github-context

is there a way we can get workflow id while running gh action?

1 Answers

Yes, it's possible.

You can get the run_id from the workflow Github Context.

Example for the Github Context from a PR event:

{
  "token": "***",
  "job": "github-context",
  "ref": "refs/pull/16/merge",
  "sha": "b4f1729888b5c99abdf8a7a250ecc6cff1e180be",
  "repository": "GuillaumeFalourd/poc-github-actions",
  "repository_owner": "GuillaumeFalourd",
  "repositoryUrl": "git://github.com/GuillaumeFalourd/poc-github-actions.git",
  "run_id": "974568708",
  "run_number": "2",
  "retention_days": "90",
  "actor": "GuillaumeFalourd",
  "workflow": "24 - Github Context",
  "head_ref": "feature/readme",
  "base_ref": "main",
  "event_name": "pull_request",
  "event": {...}
} 
Related