create-trigger
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCreate Trigger
创建触发器
Generate Harness Trigger YAML and push to Harness via MCP.
生成Harness Trigger YAML并通过MCP推送到Harness平台。
Instructions
操作步骤
- Identify trigger type - Webhook (Git events), Scheduled (cron), Artifact (registry updates), or Manifest (Helm chart updates)
- Configure conditions - Branch filters, payload conditions, cron expression, or artifact path
- Generate YAML using the templates below, referencing the target pipeline
- Create via MCP using with resource_type
harness_createtrigger - Verify webhook registration - For webhook triggers, confirm the webhook is registered in the Git provider
- 确定触发器类型 - Webhook(Git事件)、定时(Cron)、制品(镜像仓库更新)或清单(Helm Chart更新)
- 配置触发条件 - 分支过滤、负载条件、Cron表达式或制品路径
- 使用下方模板生成YAML,关联目标流水线
- 通过MCP创建:调用,设置resource_type为
harness_createtrigger - 验证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事件类型
- - Code pushed to branch
Push - - PR events (Open, Close, Reopen, Synchronize, Edit)
PullRequest - - PR comments (Create, Edit, Delete)
IssueComment - - Release events (Create, Publish, Edit)
Release
- - 代码推送到分支
Push - - PR事件(打开、关闭、重新打开、同步、编辑)
PullRequest - - PR评论(创建、编辑、删除)
IssueComment - - 发布事件(创建、发布、编辑)
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: mainyaml
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: mainScheduled (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: mainCron 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: mainCron格式:
<分钟> <小时> <日期> <月份> <星期>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_serviceyaml
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_serviceArtifact Source Types
制品源类型
- - Docker Hub
DockerRegistry - - AWS ECR
Ecr - - Google Container Registry
Gcr - - Azure Container Registry
Acr - - Nexus
Nexus3Registry - - S3 artifacts
AmazonS3
- - Docker Hub
DockerRegistry - - AWS ECR
Ecr - - Google Container Registry
Gcr - - Azure Container Registry
Acr - - Nexus
Nexus3Registry - - S3制品
AmazonS3
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: , , , ,
sourceBranchtargetBranchrefactiontag通过Webhook负载过滤触发器:
yaml
payloadConditions:
- key: targetBranch
operator: Equals # Equals, NotEquals, In, NotIn, StartsWith, EndsWith, Contains, Regex
value: main
- key: sourceBranch
operator: StartsWith
value: feature/常用键值:, , , ,
sourceBranchtargetBranchrefactiontagExamples
示例
- "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 on the trigger to verify config
harness_get
- 验证Git服务商中已注册Webhook
- 检查负载条件与实际负载匹配
- 确保连接器拥有正确权限
- 使用查询触发器以验证配置
harness_get
Duplicate Executions
重复执行
- Enable for PR triggers
autoAbortPreviousExecutions - 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时区)
- 检查流水线标识符是否正确
- 确保触发器已启用