Custom Deployment Process
About 1086 wordsAbout 4 min
Cloud Native Build supports custom deployment workflows with configurable deployment environments, approval processes, and deployment pipelines for automated releases.

Custom Deployment Environments
Add a .cnb/tag_deploy.yml file in the repository root directory to configure deployment environments. The example below defines three environments: development, staging, and production. Users can select the desired environment type on the page.
Basic Example
Simplest configuration, defining three deployment environments:
environments:
- name: development
description: Development environment
env:
name: development
tag_name: $CNB_BRANCH
- name: staging
description: Staging environment
env:
name: staging
tag_name: $CNB_BRANCH
- name: production
description: Production environment
env:
name: production
tag_name: $CNB_BRANCHPermission Control
Use permissions to restrict deployment execution:
environments:
- name: production
description: Production environment
permissions:
roles:
- master
- developer
users:
- name1
- name2Custom Buttons (button)
Add button in environment config to trigger custom web_trigger events:
environments:
- name: production
description: Production environment
button:
- name: Generate Release Notes
description: Auto-generate Release Notes
event: web_trigger_release_notes
env:
a: 1
b: 2Custom Deploy Buttons (deploy)
In multi-module scenarios, use deploy to configure multiple deploy buttons, distinguished by env:
environments:
- name: production
description: Production environment
deploy:
- name: Deploy Frontend
env:
module: frontend
- name: Deploy Backend
env:
module: backend
deploybutton env vars can only be pre-configured viaenv, not entered by users on the page. Deployment is a serious operation; related parameters should be version-controlled.
Field Reference
name: Required, environment name, must be unique (e.g.name: development). Clicking the corresponding deploy button triggers thetag_deploy.developmentevent in.cnb.yml.description: Optional, environment description.title: Optional, custom-triggered deployment pipeline title.env: Optional, environment variables passed to deployment pipeline.permissions: Optional. Deployment permission control. Users who meet either theusersorrolescondition will have deployment permission (in addition to having repository write permission). Ifpermissionsis not configured, users with repository write permission and tag push permission can trigger the build.users: Optional.Array<String>. Array of usernames. Multiple usernames can be defined.roles: Optional.Array<String>. Array of repository roles:owner,master,developer,reporter,guest. Roles are not upwardly inclusive.
button: Optional, array of objects, custom buttons. Clicking button triggers Cloud Native Build pipeline for specified event.name: Required, button name.description: Optional, button description.event: Required, custom event, only supports web_trigger events.isDefault: Optional,Boolean. Only one default button is supported.env: Optional, environment variables passed to web_trigger pipeline.permissions: Optional, permission control.inputs: Optional, manually input environment variables, supportinginput,textarea,select,switch,radiotypes, also supporting grouping. See Web Trigger - Custom Button Configuration for details.
deploy: Optional, array of objects, custom deploy buttons for deployment events (tag_deploy.*).name: Required, button name.description: Optional, button description.title: Optional, custom-triggered deployment pipeline title. Priority is higher than parent's title.env: Optional, environment variables passed to deployment pipeline, higher priority than parent env.
require: Optional, array of objects. Pre-deployment conditions must all be met. Supports three types:- Environment Requirement:
environmentName(required) +after(optional, in seconds) - Annotation Requirement:
annotation(required) +expect(optional, supportseq/ne/gt/lt/gte/lte/and/or/reg) - Approval Requirement:
approver(required, supportsusersandroles),title(optional),agreeEvent/rejectEvent(optional)
See Custom Deployment Preconditions section below for examples.
- Environment Requirement:
Custom Deployment Preconditions
Preconditions can be defined for each environment, and deployment can only proceed if all preconditions are met. The following three types of preconditions can be defined:
- Environment Deployment Requirement: Requires that a specified environment has been deployed successfully and meets the
aftertime requirement. - Annotation Value Requirement: Requires that the value of a specified annotation key meets certain conditions.
- Approval Process Requirement: Allows custom approval processes with designated approvers. Only when all approval steps are approved is the requirement considered satisfied.
Environment Deployment Preconditions
environments:
- name: development
description: Development environment
env:
name: development
tag_name: $CNB_BRANCH
- name: staging
description: Staging environment
env:
name: staging
tag_name: $CNB_BRANCH
require:
- environmentName: development
- name: production
description: Production environment
require:
- environmentName: staging
after: 1800 # Requires staging deployed 30 minutes agoAnnotation Preconditions
environments:
- name: production
description: Production environment
require:
- annotation: key1 # Must have a value
- annotation: key2
expect:
eq: value2 # Must equal value2
- annotation: key3
expect:
and:
gt: 1
lt: 10 # Must be >1 and <10
button:
- name: Generate Annotation
event: web_trigger_annotation
description: Generate Annotation Workflow
env:
name1: value1Approval Process Preconditions
Custom approval processes and designated approvers can be defined. Authorized approvers can perform approval actions (approve or reject). The requirement is considered satisfied only when all approval steps are approved.
environments:
- name: production
description: Production environment
require:
- approver:
users:
- user1
- user2
title: Test Approval
- approver:
roles:
- developer
- master
title: Development Approval
- approver:
users:
- user4
roles:
- master
- owner
title: Operations ApprovalCustom Deployment Pipelines
The example below defines deployment pipelines for three environments. When selecting development environment on the page, it triggers the tag_deploy.development event. The pipeline performs deployment operations based on the code corresponding to the current tag.
$:
tag_deploy.development:
- name: dev
stages:
- name: Environment name
script: echo $name
- name: Tag name
script: echo $tag_name
tag_deploy.staging:
- stages:
- echo $name
- echo $tag_name
tag_deploy.production:
- stages:
- echo $name
- echo $tag_nameCustom Button Web_trigger Events
Custom buttons in tag_deploy.yml can only trigger web_trigger events. In the pipeline configuration below, the web_trigger_annotation event uploads Annotation when executed.
$:
web_trigger_annotation:
- stages:
- name: Upload Annotation
image: cnbcool/annotations:latest
settings:
data: |
key1=value1
key2=value2Deployment Permissions
By default, users with repository write permission and tag push permission can perform deployment operations.
If the permissions field is configured, users must have both repository write permission and the permissions defined in the permissions field. In this case, tag push permission is no longer checked.
Rebuild Restrictions
To prevent deployment operations from being replayed by others, builds triggered by deployment events (tag_deploy.*) have the following rebuild restrictions:
- Only the original pipeline trigger can rebuild; other users cannot.
- Rebuild is only allowed within 24 hours after the original build; rebuilds are not allowed after 24 hours.
If a redeployment is needed after 24 hours or by a different user, please initiate a new deployment from the Tag details page to ensure pre-deployment checks and approval workflows are followed.