gitlab通过web_hook触发jenkins任务

1. jenkins hook配置

SourceCodeManagement

Source Code Management 配置需编译的分支名
1. gitlab通过web_hook触发jenkins任务.md

目前此处指定固定git分支,若支持动态tag或分支,此处需以其他方式确定代码来源

使用插件:Generic Webhook Trigger Plugin

  • 配置Post content parameters
  1. 获取报文字段,字段名前缀为allgit
    allgit数据示例
    1. gitlab通过web_hook触发jenkins任务.md

  2. 获取commit的message内容
    1. gitlab通过web_hook触发jenkins任务.md

  • 配置token
    1. gitlab通过web_hook触发jenkins任务.md

gitlab配置hook地址时携带该验证内容

  • 配置触发的匹配字段和正则
    1. gitlab通过web_hook触发jenkins任务.md匹配字段:
  1. $allgit_project_ssh_url

git路径,eg: [email protected]:gitlabtest/spring-boot-springbootbase.git

  1. $allgit_object_kind

gitlab触发事件类型,eg: pushtag_push

  1. $allgit_ref

触发的分支或tag等,eg: refs/heads/devrefs/tags/v0.3

  1. $commit_messages

push时,commit messages的汇总,可用来匹配关键字以作为触发构建条件

2. gitlab钩子配置

project -> Settings -> Integrations -> Add webhook

  • url:http://[jenkisIP]/generic-webhook-trigger/invoke?token=[token]
  • 勾选触发hook的事件
    1. gitlab通过web_hook触发jenkins任务.md

3.allgit数据示例

1. gitlab通过web_hook触发jenkins任务.md

尾巴

至此,jenkins job已可由git触发,该job可以是maven job、freestyle project,也可是pipeline

hook传过来的参数在构建过程中怎么使用呢?

相关文章: