create-trigger

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create Trigger

创建触发器

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

Instructions

操作步骤

  1. Identify trigger type - Webhook (Git events), Scheduled (cron), Artifact (registry updates), or Manifest (Helm chart updates)
  2. Configure conditions - Branch filters, payload conditions, cron expression, or artifact path
  3. Generate YAML using the templates below, referencing the target pipeline
  4. Create via MCP using
    harness_create
    with resource_type
    trigger
  5. Verify webhook registration - For webhook triggers, confirm the webhook is registered in the Git provider
  1. 确定触发器类型 - Webhook(Git事件)、定时(Cron)、制品(镜像仓库更新)或清单(Helm Chart更新)
  2. 配置触发条件 - 分支过滤、负载条件、Cron表达式或制品路径
  3. 使用下方模板生成YAML,关联目标流水线
  4. 通过MCP创建:调用
    harness_create
    ,设置resource_type为
    trigger
  5. 验证Webhook注册 - 对于Webhook触发器,确认Git服务商中已注册该Webhook

Trigger Types

触发器类型

  • Webhook - GitHub, GitLab, Bitbucket, Azure Repos, Custom
  • Scheduled - Cron-based scheduling
  • Artifact - Docker Hub, ECR, GCR, ACR, Nexus
  • Manifest - Helm chart updates
  • Webhook - GitHub、GitLab、Bitbucket、Azure Repos、自定义类型
  • 定时 - 基于Cron的调度
  • 制品 - Docker Hub、ECR、GCR、ACR、Nexus
  • 清单 - Helm Chart更新

Webhook Trigger (GitHub)

Webhook Trigger (GitHub)

yaml
trigger:
  name: PR Trigger
  identifier: pr_trigger
  orgIdentifier: default
  projectIdentifier: my_project
  pipelineIdentifier: ci_pipeline
  source:
    type: Webhook
    spec:
      type: Github
      spec:
        type: PullRequest
        spec:
          connectorRef: github_connector
          autoAbortPreviousExecutions: true
          payloadConditions:
            - key: targetBranch
              operator: Equals
              value: main
          headerConditions: []
          jexlCondition: ""
          actions:
            - Open
            - Reopen
            - Synchronize
  inputYaml: |
    pipeline:
      identifier: ci_pipeline
      properties:
        ci:
          codebase:
            build:
              type: PR
              spec:
                number: <+trigger.prNumber>
yaml
trigger:
  name: PR Trigger
  identifier: pr_trigger
  orgIdentifier: default
  projectIdentifier: my_project
  pipelineIdentifier: ci_pipeline
  source:
    type: Webhook
    spec:
      type: Github
      spec:
        type: PullRequest
        spec:
          connectorRef: github_connector
          autoAbortPreviousExecutions: true
          payloadConditions:
            - key: targetBranch
              operator: Equals
              value: main
          headerConditions: []
          jexlCondition: ""
          actions:
            - Open
            - Reopen
            - Synchronize
  inputYaml: |
    pipeline:
      identifier: ci_pipeline
      properties:
        ci:
          codebase:
            build:
              type: PR
              spec:
                number: <+trigger.prNumber>

GitHub Event Types

GitHub事件类型

  • Push
    - Code pushed to branch
  • PullRequest
    - PR events (Open, Close, Reopen, Synchronize, Edit)
  • IssueComment
    - PR comments (Create, Edit, Delete)
  • Release
    - Release events (Create, Publish, Edit)
  • Push
    - 代码推送到分支
  • PullRequest
    - PR事件(打开、关闭、重新打开、同步、编辑)
  • IssueComment
    - PR评论(创建、编辑、删除)
  • Release
    - 发布事件(创建、发布、编辑)

Webhook Trigger (GitLab)

Webhook Trigger (GitLab)

yaml
trigger:
  name: GitLab Push
  identifier: gitlab_push
  pipelineIdentifier: ci_pipeline
  source:
    type: Webhook
    spec:
      type: Gitlab
      spec:
        type: Push
        spec:
          connectorRef: gitlab_connector
          payloadConditions:
            - key: ref
              operator: Contains
              value: main
yaml
trigger:
  name: GitLab Push
  identifier: gitlab_push
  pipelineIdentifier: ci_pipeline
  source:
    type: Webhook
    spec:
      type: Gitlab
      spec:
        type: Push
        spec:
          connectorRef: gitlab_connector
          payloadConditions:
            - key: ref
              operator: Contains
              value: main

Scheduled (Cron) Trigger

定时(Cron)触发器

yaml
trigger:
  name: Nightly Build
  identifier: nightly_build
  orgIdentifier: default
  projectIdentifier: my_project
  pipelineIdentifier: ci_pipeline
  source:
    type: Scheduled
    spec:
      type: Cron
      spec:
        expression: "0 2 * * *"    # 2 AM daily
  inputYaml: |
    pipeline:
      identifier: ci_pipeline
      properties:
        ci:
          codebase:
            build:
              type: branch
              spec:
                branch: main
Cron format:
<minute> <hour> <day-of-month> <month> <day-of-week>
yaml
trigger:
  name: Nightly Build
  identifier: nightly_build
  orgIdentifier: default
  projectIdentifier: my_project
  pipelineIdentifier: ci_pipeline
  source:
    type: Scheduled
    spec:
      type: Cron
      spec:
        expression: "0 2 * * *"    # 每日凌晨2点
  inputYaml: |
    pipeline:
      identifier: ci_pipeline
      properties:
        ci:
          codebase:
            build:
              type: branch
              spec:
                branch: main
Cron格式:
<分钟> <小时> <日期> <月份> <星期>

Artifact Trigger (Docker Registry)

制品触发器(Docker镜像仓库)

yaml
trigger:
  name: New Image Trigger
  identifier: new_image
  pipelineIdentifier: deploy_pipeline
  source:
    type: Artifact
    spec:
      type: DockerRegistry
      spec:
        connectorRef: dockerhub
        imagePath: myorg/myimage
        tag: <+trigger.artifact.build>
  inputYaml: |
    pipeline:
      identifier: deploy_pipeline
      stages:
        - stage:
            identifier: deploy
            spec:
              service:
                serviceRef: my_service
yaml
trigger:
  name: New Image Trigger
  identifier: new_image
  pipelineIdentifier: deploy_pipeline
  source:
    type: Artifact
    spec:
      type: DockerRegistry
      spec:
        connectorRef: dockerhub
        imagePath: myorg/myimage
        tag: <+trigger.artifact.build>
  inputYaml: |
    pipeline:
      identifier: deploy_pipeline
      stages:
        - stage:
            identifier: deploy
            spec:
              service:
                serviceRef: my_service

Artifact Source Types

制品源类型

  • DockerRegistry
    - Docker Hub
  • Ecr
    - AWS ECR
  • Gcr
    - Google Container Registry
  • Acr
    - Azure Container Registry
  • Nexus3Registry
    - Nexus
  • AmazonS3
    - S3 artifacts
  • DockerRegistry
    - Docker Hub
  • Ecr
    - AWS ECR
  • Gcr
    - Google Container Registry
  • Acr
    - Azure Container Registry
  • Nexus3Registry
    - Nexus
  • AmazonS3
    - S3制品

Creating via MCP

通过MCP创建

Call MCP tool: harness_create
Parameters:
  resource_type: "trigger"
  org_id: "<organization>"
  project_id: "<project>"
  body: <trigger YAML>
To list existing triggers:
Call MCP tool: harness_list
Parameters:
  resource_type: "trigger"
  org_id: "<organization>"
  project_id: "<project>"
Call MCP tool: harness_create
Parameters:
  resource_type: "trigger"
  org_id: "<organization>"
  project_id: "<project>"
  body: <trigger YAML>
列出已有触发器:
Call MCP tool: harness_list
Parameters:
  resource_type: "trigger"
  org_id: "<organization>"
  project_id: "<project>"

Payload Conditions

负载条件

Filter triggers by webhook payload:
yaml
payloadConditions:
  - key: targetBranch
    operator: Equals        # Equals, NotEquals, In, NotIn, StartsWith, EndsWith, Contains, Regex
    value: main
  - key: sourceBranch
    operator: StartsWith
    value: feature/
Common keys:
sourceBranch
,
targetBranch
,
ref
,
action
,
tag
通过Webhook负载过滤触发器:
yaml
payloadConditions:
  - key: targetBranch
    operator: Equals        # Equals, NotEquals, In, NotIn, StartsWith, EndsWith, Contains, Regex
    value: main
  - key: sourceBranch
    operator: StartsWith
    value: feature/
常用键值:
sourceBranch
,
targetBranch
,
ref
,
action
,
tag

Examples

示例

  • "Create a GitHub PR trigger for CI" - Webhook trigger with PullRequest type
  • "Set up nightly builds at 2 AM" - Scheduled trigger with cron
  • "Trigger deploy when new Docker image is pushed" - Artifact trigger with DockerRegistry
  • "Create a release trigger for tags" - Webhook with Push type, tag filter
  • "为CI创建GitHub PR触发器" - 类型为PullRequest的Webhook触发器
  • "设置凌晨2点的 nightly builds" - 带Cron表达式的定时触发器
  • "推送新Docker镜像时触发部署" - 类型为DockerRegistry的制品触发器
  • "为标签创建发布触发器" - 带标签过滤的Push类型Webhook触发器

Performance Notes

性能注意事项

  • Verify payload conditions match actual webhook payloads from the Git provider.
  • For cron triggers, double-check the expression — cron uses UTC timezone.
  • Confirm the target pipeline identifier and inputYaml match the pipeline's expected inputs.
  • 验证负载条件与Git服务商实际Webhook负载匹配。
  • 对于Cron触发器,仔细检查表达式——Cron使用UTC时区。
  • 确认目标流水线标识符和inputYaml与流水线预期输入匹配。

Troubleshooting

故障排查

Trigger Not Firing

触发器未触发

  • Verify webhook is registered in Git provider
  • Check payload conditions match actual payload
  • Ensure connector has correct permissions
  • Test with
    harness_get
    on the trigger to verify config
  • 验证Git服务商中已注册Webhook
  • 检查负载条件与实际负载匹配
  • 确保连接器拥有正确权限
  • 使用
    harness_get
    查询触发器以验证配置

Duplicate Executions

重复执行

  • Enable
    autoAbortPreviousExecutions
    for PR triggers
  • Check for overlapping trigger conditions
  • 为PR触发器启用
    autoAbortPreviousExecutions
  • 检查是否存在重叠的触发条件

Cron Not Running

Cron未运行

  • Verify cron expression syntax (5 fields, UTC timezone)
  • Check pipeline identifier is correct
  • Ensure trigger is enabled
  • 验证Cron表达式语法(5个字段,UTC时区)
  • 检查流水线标识符是否正确
  • 确保触发器已启用