---
url: /zh/build/internal-steps/cnb/destroy-token.md
description: |
  提前销毁 CNB_TOKEN 并移除对应环境变量， 用于流水线中不再需要令牌、希望尽早收回权限的场景，降低令牌被误用的风险。
---
`cnb:destroy-token`

流水线启动前自动创建 [CNB\_TOKEN](../../build-in-env.md#cnb_token)，
结束后自动销毁。使用该任务可提前销毁 CNB\_TOKEN 并移除对应环境变量。

**使用场景**：流水线中不再需要 CNB\_TOKEN、又想尽早收回权限时使用——例如在已完成
需要令牌的操作后主动销毁令牌，降低令牌在后续任务中被误用、滥用的风险。
流水线结束时平台会自动销毁，本任务用于把销毁时机提前。

* [适用事件](#cnb-destroy-token-applicable-events)
* [参数](#cnb-destroy-token-parameters)
* [输出结果](#cnb-destroy-token-output)
* [配置样例](#cnb-destroy-token-configuration-examples)

## 适用事件 {#cnb-destroy-token-applicable-events}

[所有事件](../../trigger-rule.md#trigger-event)

## 参数 {#cnb-destroy-token-parameters}

无

## 输出结果 {#cnb-destroy-token-output}

无

## 配置样例 {#cnb-destroy-token-configuration-examples}

流水线中使用 CNB\_TOKEN 后主动销毁，降低令牌滥用风险。

```yaml title=".cnb.yml"
main:
  push:
    - stages:
        - name: use CNB_TOKEN
          script: echo "Make API calls using the CNB_TOKEN."
        - name: destroy token
          type: cnb:destroy-token
```
