When a job calls a reusable workflow using uses:, you can control which secrets the called workflow can access by configuring jobs.<job_id>.secrets:
-
inherit— Make all secrets in the caller job’s scope available to the reusable workflow. -
Mapping — Expose only specific secrets by mapping them one-by-one.
Use inherit with trusted reusable workflows only. If a job in the reusable workflow runs in an environment, environment-scoped secrets for that job are resolved and can override inherited or mapped values.
|
If a job sets |
Inherit all secrets
In this example, caller-job invokes a reusable workflow and inherits all secrets from its scope.
jobs: caller-job: uses: .cloudbees/workflows/a-reusable-workflow.yaml (1) secrets: inherit (2) inputs: env-prod: production (3)
| 1 | Calls a reusable workflow from the current repository. |
| 2 | Inherits all secrets from the caller job’s scope. |
| 3 | Passes an environment name as input to the reusable workflow (optional). |
| 1 | Sets the job’s environment from the input; environment-scoped secrets are resolved for this job. |
Map specific secrets
In this example, only two secrets are exposed to the reusable workflow. No other caller secrets are available.
jobs: caller-job: uses: .cloudbees/workflows/a-reusable-workflow.yaml secrets: (1) secret-1: ${{ secrets.SECRET_A }} (2) secret-2: ${{ secrets.SECRET_B }} (3) inputs: env-prod: production
| 1 | Uses mapping instead of inheritance. |
| 2 | Maps caller secret SECRET_A to secret-1 for the reusable workflow. |
| 3 | Maps caller secret SECRET_B to secret-2. |
|