You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/actions/reference/workflows-and-actions/contexts.md
+36-2Lines changed: 36 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -378,15 +378,23 @@ The `job` context contains information about the currently running job.
378
378
| `job.services.<service_id>.network` | `string` | The ID of the service container network. The runner creates the network used by all containers in a job. |
379
379
| `job.services.<service_id>.ports` | `object` | The exposed ports of the service container. |
380
380
| `job.status` | `string` | The current status of the job. Possible values are `success`, `failure`, or `cancelled`. |
381
+
| `job.workflow_ref` | `string` | The full ref of the workflow file that defines the current job. For example, `octo-org/octo-repo/.github/workflows/deploy.yml@refs/heads/main`. For jobs defined directly in a workflow file, this is the same as `github.workflow_ref`. For jobs defined in a [AUTOTITLE](/actions/using-workflows/reusing-workflows), this refers to the reusable workflow file. (not available on {% data variables.product.prodname_ghe_server %}) |
382
+
| `job.workflow_sha` | `string` | The commit SHA of the workflow file that defines the current job. (not available on {% data variables.product.prodname_ghe_server %}) |
383
+
| `job.workflow_repository` | `string` | The `owner/repo` of the repository containing the workflow file that defines the current job. For example, `octo-org/octo-repo`. (not available on {% data variables.product.prodname_ghe_server %}) |
384
+
| `job.workflow_file_path` | `string` | The file path of the workflow file that defines the current job, relative to the repository root. For example, `.github/workflows/deploy.yml`. (not available on {% data variables.product.prodname_ghe_server %}) |
381
385
382
386
### Example contents of the `job` context
383
387
384
-
This example `job` context uses a PostgreSQL service container with mapped ports. If there are no containers or service containers used in a job, the `job` context only contains the `status` and `check_run_id` properties.
388
+
This example `job` context uses a PostgreSQL service container with mapped ports. If there are no containers or service containers used in a job, the `job` context only contains `status`. The `check_run_id` and workflow identity properties (`workflow_ref`, `workflow_sha`, `workflow_repository`, `workflow_file_path`) are not available on {% data variables.product.prodname_ghe_server %}.
385
389
386
390
```json
387
391
{
388
392
"status": "success",
389
-
{% ifversion fpt or ghec %}"check_run_id": 51725241954,{% endif %}
### Example usage of `job` context workflow identity
439
+
440
+
> [!NOTE]
441
+
> The `job.workflow_*` context properties are not available on {% data variables.product.prodname_ghe_server %}.
442
+
443
+
This example reusable workflow uses `job.workflow_repository` and `job.workflow_sha` to check out its own source code, rather than the caller's repository. This is useful when a reusable workflow needs to access files co-located with the workflow definition.
444
+
445
+
```yaml copy
446
+
# In a reusable workflow (e.g., octo-org/shared-workflows/.github/workflows/deploy.yml)
447
+
name: Reusable deploy workflow
448
+
on:
449
+
workflow_call:
450
+
451
+
jobs:
452
+
deploy:
453
+
runs-on: ubuntu-latest
454
+
steps:
455
+
- uses: {% data reusables.actions.action-checkout %}
456
+
with:
457
+
repository: {% raw %}${{ job.workflow_repository }}{% endraw %}
458
+
ref: {% raw %}${{ job.workflow_sha }}{% endraw %}
459
+
460
+
- run: echo "Deploying from {% raw %}${{ job.workflow_ref }}{% endraw %}"
461
+
- run: echo "Workflow file path is {% raw %}${{ job.workflow_file_path }}{% endraw %}"
462
+
```
463
+
430
464
## `jobs` context
431
465
432
466
The `jobs` context is only available in reusable workflows, and can only be used to set outputs for a reusable workflow. For more information, see [AUTOTITLE](/actions/using-workflows/reusing-workflows#using-outputs-from-a-reusable-workflow).
0 commit comments