create-environment

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create Environment

创建环境

Generate Harness Environment YAML and push to Harness via MCP.
生成Harness Environment YAML并通过MCP推送到Harness。

Instructions

操作说明

  1. Determine environment type -
    PreProduction
    for dev/staging/QA,
    Production
    for live environments
  2. Define variables and overrides - Environment-specific config values and manifest overrides
  3. Generate YAML using the structure below
  4. Create via MCP using
    harness_create
    with resource_type
    environment
  1. 确定环境类型 -
    PreProduction
    适用于dev/staging/QA环境,
    Production
    适用于生产环境
  2. 定义变量与覆盖配置 - 环境专属的配置值和清单覆盖项
  3. 使用下方结构生成YAML
  4. 通过MCP创建:调用
    harness_create
    ,指定resource_type为
    environment

Environment Structure

环境结构

yaml
environment:
  name: Staging
  identifier: staging
  orgIdentifier: default
  projectIdentifier: my_project
  type: PreProduction       # PreProduction or Production
  tags:
    tier: staging
  variables:
    - name: domain
      type: String
      value: staging.myapp.com
    - name: replicas
      type: Number
      value: "2"
    - name: db_password
      type: Secret
      value: <+secrets.getValue("staging_db_password")>
  overrides:
    manifests:
      - manifest:
          identifier: values_override
          type: Values
          spec:
            store:
              type: Github
              spec:
                connectorRef: github
                repoName: config
                branch: main
                paths: [values-staging.yaml]
yaml
environment:
  name: Staging
  identifier: staging
  orgIdentifier: default
  projectIdentifier: my_project
  type: PreProduction       # PreProduction or Production
  tags:
    tier: staging
  variables:
    - name: domain
      type: String
      value: staging.myapp.com
    - name: replicas
      type: Number
      value: "2"
    - name: db_password
      type: Secret
      value: <+secrets.getValue("staging_db_password")>
  overrides:
    manifests:
      - manifest:
          identifier: values_override
          type: Values
          spec:
            store:
              type: Github
              spec:
                connectorRef: github
                repoName: config
                branch: main
                paths: [values-staging.yaml]

Environment Types

环境类型

  • PreProduction
    - Dev, QA, staging, integration environments
  • Production
    - Live production environments (enables additional safeguards)
  • PreProduction
    - 开发、QA、staging、集成环境
  • Production
    - 生产环境(启用额外安全防护)

Multi-Environment Setup

多环境配置

Create dev, staging, and prod:
yaml
undefined
创建dev、staging和prod环境:
yaml
undefined

Dev

Dev

environment: name: Development identifier: dev type: PreProduction variables: - name: domain type: String value: dev.myapp.com
environment: name: Development identifier: dev type: PreProduction variables: - name: domain type: String value: dev.myapp.com

Staging

Staging

environment: name: Staging identifier: staging type: PreProduction variables: - name: domain type: String value: staging.myapp.com
environment: name: Staging identifier: staging type: PreProduction variables: - name: domain type: String value: staging.myapp.com

Production

Production

environment: name: Production identifier: prod type: Production variables: - name: domain type: String value: myapp.com
undefined
environment: name: Production identifier: prod type: Production variables: - name: domain type: String value: myapp.com
undefined

Creating via MCP

通过MCP创建

Call MCP tool: harness_create
Parameters:
  resource_type: "environment"
  org_id: "<organization>"
  project_id: "<project>"
  body: <environment YAML>
List environments:
Call MCP tool: harness_list
Parameters:
  resource_type: "environment"
  org_id: "<organization>"
  project_id: "<project>"
调用MCP工具:harness_create
参数:
  resource_type: "environment"
  org_id: "<organization>"
  project_id: "<project>"
  body: <environment YAML>
列出环境:
调用MCP工具:harness_list
参数:
  resource_type: "environment"
  org_id: "<organization>"
  project_id: "<project>"

Examples

示例

  • "Create dev, staging, and prod environments" - Generate 3 environments with appropriate types
  • "Set up a production environment with overrides" - Production type with manifest overrides
  • "创建dev、staging和prod环境" - 生成3个对应类型的环境
  • "搭建带覆盖配置的生产环境" - Production类型并配置清单覆盖

Performance Notes

性能注意事项

  • When creating multiple environments (dev/staging/prod), ensure variable values are distinct per environment.
  • Verify that manifest override paths exist in the referenced repository before creating.
  • Use Production type only for live environments — it enables additional safeguards like deployment freezes.
  • 创建多个环境(dev/staging/prod)时,确保每个环境的变量值唯一。
  • 创建前验证清单覆盖路径在引用的仓库中存在。
  • 仅在生产环境使用Production类型——它会启用部署冻结等额外安全防护。

Troubleshooting

故障排查

  • DUPLICATE_IDENTIFIER
    - Environment exists; use
    harness_update
  • Production type enables deployment freeze and approval guardrails
  • DUPLICATE_IDENTIFIER
    - 环境已存在;使用
    harness_update
    更新
  • Production类型会启用部署冻结和审批防护机制