jobs.<job_id>.environment

1 minute read

Use jobs.<job_id>.environment to define the environment that the job references.

  • The only deployment protection rule for CloudBees platform is the indicator that an environment requires an approval.

  • If the referenced environment has manual approvals enabled, the job does not start until approved.

  • Once the job is approved and started, the properties defined in the environment are made available to the job, using standard vars.* and secrets.* expressions.

  • You can also specify the environment via an expression that evaluates to an environment name (for example, ${{ inputs.target_env }}). The expression is resolved to an environment name before* environment-scoped vars and secrets are evaluated and before any required approval is requested.

Provide the environment as the environment name—either as a literal string or as an expression that resolves to a name:

Literal name
environment: dev
Expression that resolves to a name
environment: ${{ inputs.target_env }}
If you use the Register an artifact deployed to an environment action in a workflow run, its target-environment value overrides jobs.<job_id>.environment.

Using job.environment in called workflows

Use job.environment to pass the current job’s evaluated environment name to a reusable workflow, avoiding hard-coded strings.

Example: avoid hard-coding the environment
deploy: uses: org/repo/reusable.yaml environment: QA secrets: asecret: ${{ secrets.secret1 }} with: aninput: ${{ vars.avalue }} artifactName: ${{ inputs.artifactName }} artifactVersion: ${{ inputs.artifactVersion }} environment: ${{ job.environment }} # resolves to "QA"
Example: dynamic environment via expression
deploy: uses: org/repo/reusable.yaml environment: ${{ inputs.target_env }} # for example: "QA", "staging", "prod" with: environment: ${{ job.environment }} # returns the evaluated name