我想在合并请求的gitlab中为CI运行一些工作。
我创建了一个webhook和一个触发器,并且webhook会在Merge请求事件上触发
此触发器被触发两次:在创建和合并时。
我不希望在合并时触发该触发器,因为对我来说没用。
我该如何解决这个问题?
谢谢
我记得在我的情况下推送事件工作正常
https://开头{$ jenkins.url} /git/notifyCommit?url=ssh://[email protected]:2222/ {$组} / {$项目}的.git
扩大Joao Vitorino的答案。通过webhook接收到json数据后,您可以根据“action”的值做出决定。您可以在“object_attributes”对象中找到它。
"object_attributes": {
"assignee_id": 20,
"author_id": 20,
"created_at": "2018-09-04 09:39:25 UTC",
"description": "blub\\r\\nblub2",
"head_pipeline_id": null,
"id": 85,
"iid": 3,
"last_edited_at": "2018-09-04 09:50:21 UTC",
"last_edited_by_id": 20,
"merge_commit_sha": "035683abb9eae299399210ddd79a0f3b93bc4bbd",
"merge_error": null,
"merge_params": {
"force_remove_source_branch": "0"
},
"merge_status": "can_be_merged",
"merge_user_id": null,
"merge_when_pipeline_succeeds": false,
"milestone_id": null,
"source_branch": "sourceBranch",
"source_project_id": 34,
"state": "merged",
"target_branch": "develop",
"target_project_id": 34,
"time_estimate": 0,
"title": "Feature/olatce 11380",
"updated_at": "2018-09-04 09:50:25 UTC",
"updated_by_id": 20,
"url": "url-to-gitlab.com",
"source": {
},
"target": {
},
"last_commit": {
},
"work_in_progress": false,
"total_time_spent": 0,
"human_total_time_spent": null,
"human_time_estimate": null,
"action": "merge"
},
它是对象中的最后一个字段,可以具有以下值:
有了这个,您应该能够决定如何处理触发器。
你可以使用Generic Webhook Trigger Plugin。
如果配置这些变量:
MR_OBJECT_KIND
为$.object_kind
MR_ACTION
为$.object_attributes.action
MR_OLD_REV
为$.object_attributes.oldrev
并且过滤文本为:$MR_OBJECT_KIND $MR_ACTION $MR_OLD_REV
过滤表达式为:^merge_request\s(update\s.{40}$|open.*)
然后,作业应仅在创建或更新时触发。