|
1 | 1 | --- |
2 | 2 | title: Deploying with GitHub Actions |
3 | 3 | shortTitle: Control deployments |
4 | | -intro: Learn how to control deployments with features like environments and concurrency. |
| 4 | +intro: '{% data variables.product.prodname_actions %} gives you fine-grained control over deployments with environments, concurrency groups, and protection rules.' |
5 | 5 | versions: |
6 | 6 | fpt: '*' |
7 | 7 | ghes: '*' |
@@ -54,8 +54,54 @@ You can configure environments with protection rules and secrets. When a workflo |
54 | 54 |
|
55 | 55 | Concurrency ensures that only a single job or workflow using the same concurrency group will run at a time. You can use concurrency so that an environment has a maximum of one deployment in progress and one deployment pending at a time. For more information about concurrency, see [AUTOTITLE](/actions/using-jobs/using-concurrency). |
56 | 56 |
|
57 | | -> [!NOTE] |
58 | | -> `concurrency` and `environment` are not connected. The concurrency value can be any string; it does not need to be an environment name. Additionally, if another workflow uses the same environment but does not specify concurrency, that workflow will not be subject to any concurrency rules. |
| 57 | +{% ifversion actions-environments-without-deployments %} |
| 58 | +
|
| 59 | +## Using environments without deployments |
| 60 | +
|
| 61 | +By default, when a workflow job references an environment, {% data variables.product.company_short %} creates a deployment object to track the deployment. You can opt out of deployment creation by setting `deployment` to `false` in the environment configuration. The valid values are `true` (default) and `false`. You can also use an expression, for example `deployment: {% raw %}${{ github.ref_name == 'main' }}{% endraw %}`. |
| 62 | + |
| 63 | +```yaml |
| 64 | +jobs: |
| 65 | + test: |
| 66 | + runs-on: ubuntu-latest |
| 67 | + environment: |
| 68 | + name: staging |
| 69 | + deployment: false |
| 70 | + steps: |
| 71 | + - name: run tests |
| 72 | + env: |
| 73 | + API_KEY: {% raw %}${{ secrets.API_KEY }}{% endraw %} |
| 74 | + run: echo "Running tests with staging secrets" |
| 75 | +``` |
| 76 | + |
| 77 | +When `deployment` is set to `false`: |
| 78 | + |
| 79 | +* The job has full access to environment secrets and variables. |
| 80 | +* No {% data variables.product.github %} deployment object is created—the deployment history for the environment is not updated. |
| 81 | +* Wait timer protection rules still apply—the job waits for the configured duration. |
| 82 | +* Required reviewers still apply—reviewers must still approve before the job runs. |
| 83 | + |
| 84 | +This is useful when you want to use environments for: |
| 85 | + |
| 86 | +* **Organizing secrets**—group related secrets under an environment name without creating deployment records. |
| 87 | +* **Access control**—restrict which branches can use certain secrets via environment branch policies, without deployment tracking. |
| 88 | +* **CI and testing jobs**—reference an environment for its configuration without adding noise to the deployment history. |
| 89 | + |
| 90 | +### Interaction with protection rules |
| 91 | + |
| 92 | +The `deployment` property controls which protection rules apply: |
| 93 | + |
| 94 | +| Protection rule | `deployment: true` (default) | `deployment: false` | |
| 95 | +|----------------|------------------------------|---------------------| |
| 96 | +| **None** | Deployment created, job runs | No deployment, job runs | |
| 97 | +| **Wait timer** | Wait timer enforced | Wait timer still enforced | |
| 98 | +| **Required reviewers** | Reviewers must approve | Reviewers must approve | |
| 99 | +| **Custom deployment protection rule app** | App webhook sent, must approve | **Job fails with error** | |
| 100 | + |
| 101 | +Custom deployment protection rules ({% data variables.product.prodname_github_apps %}) require a deployment object to function. If you set `deployment: false` on an environment that has custom deployment protection rules, the job will fail immediately with an annotation or error message explaining that the environment's protection rules are incompatible with `deployment: false`. Either remove `deployment: false` from your workflow, or remove the custom deployment protection rules from the environment. |
| 102 | + |
| 103 | +Note that `concurrency` and `environment` are not connected. The concurrency value can be any string; it does not need to be an environment name. Additionally, if another workflow uses the same environment but does not specify concurrency, that workflow will not be subject to any concurrency rules. |
| 104 | +{% endif %} |
59 | 105 |
|
60 | 106 | For example, when the following workflow runs, it will be paused with the status `pending` if any job or workflow that uses the `production` concurrency group is in progress. It will also cancel any job or workflow that uses the `production` concurrency group and has the status `pending`. This means that there will be a maximum of one running and one pending job or workflow in that uses the `production` concurrency group. |
61 | 107 |
|
|
0 commit comments