'In GitHub Actions, how can I uniquely identify the workflow under execution?
I am using GitHub Enterprise, with a self-hosted runner. I'm storing build artifacts in dedicated folders so that I can have multiple releases in the same pipeline, without worrying about overwriting old artifacts with new releases.
I'm storing my artifacts using this folder scheme:
ARTIFACTS_PATH: "c:/github/artifacts/${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ github.run_id }}"
This helps me ensure each workflow run gets its own directory. But my issue now is I want to implement a "rolling delete", where after each workflow completes it deletes all but the last 5 artifact folders related to that workflow. But for that I need to be able to map the artifact folders to specific workflows.
So what I'd like to have is something that looks like this, but the workflow_id environment variable doesn't exist.
ARTIFACTS_PATH: "c:/github/artifacts/${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ github.workflow_id }}/${{ github.run_number }}"
Is there any way I can unique identify the workflow being executed through a unique id or something similar?
Solution 1:[1]
You can either use the workflow file name (unique, as the workflow files have to be stored directly in the folder .github/workflows) or the workflow id.
The workflow id can be determined by
getting the workflow id from a run id via the GitHub Actions REST API. The run id is available via the expression
${{github.run_id}}.
source: https://docs.github.com/en/rest/reference/actions#get-a-workflow-rungetting the workflow id by specifying the workflow file name as parameter via the GitHub Actions REST API.
Source: https://docs.github.com/en/rest/reference/actions#get-a-workflow
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
