同4.1/4.2/4.3操作
防止新建分支的时候触发自动构建
新建分支触发流水线会生成”before”:”0000000000000000000000000000000000000000”字段
4.4.1、报文
{"object_kind":"push","event_name":"push","before":"216c57c5f0118b56be76b8132b2410995d20a261","after":"f283241bd69f7b7b81cce6793e0497f475bfa434","ref":"refs/heads/master","checkout_sha":"f283241bd69f7b7b81cce6793e0497f475bfa434","message":null,"user_id":1,"user_name":"Administrator","user_username":"root","user_email":"","user_avatar":"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon","project_id":2,"project":{"id":2,"name":"demo-maven-service","description":"","web_url":"http://39.105.58.61:9999/root/demo-maven-service","avatar_url":null,"git_ssh_url":"git@39.105.58.61:root/demo-maven-service.git","git_http_url":"http://39.105.58.61:9999/root/demo-maven-service.git","namespace":"Administrator","visibility_level":0,"path_with_namespace":"root/demo-maven-service","default_branch":"master","ci_config_path":null,"homepage":"http://39.105.58.61:9999/root/demo-maven-service","url":"git@39.105.58.61:root/demo-maven-service.git","ssh_url":"git@39.105.58.61:root/demo-maven-service.git","http_url":"http://39.105.58.61:9999/root/demo-maven-service.git"},"commits":[{"id":"f283241bd69f7b7b81cce6793e0497f475bfa434","message":"Update pom.xml","title":"Update pom.xml","timestamp":"2021-02-22T20:08:00+08:00","url":"http://39.105.58.61:9999/root/demo-maven-service/-/commit/f283241bd69f7b7b81cce6793e0497f475bfa434","author":{"name":"Administrator","email":"admin@example.com"},"added":[],"modified":["pom.xml"],"removed":[]},{"id":"335e04f8656e332d1c02b39d2d7b43343bd8899e","message":"Update pom.xml","title":"Update pom.xml","timestamp":"2021-02-22T20:06:02+08:00","url":"http://39.105.58.61:9999/root/demo-maven-service/-/commit/335e04f8656e332d1c02b39d2d7b43343bd8899e","author":{"name":"Administrator","email":"admin@example.com"},"added":[],"modified":[],"removed":[]},{"id":"216c57c5f0118b56be76b8132b2410995d20a261","message":"Delete build.groovy","title":"Delete build.groovy","timestamp":"2021-02-22T18:05:30+08:00","url":"http://39.105.58.61:9999/root/demo-maven-service/-/commit/216c57c5f0118b56be76b8132b2410995d20a261","author":{"name":"Administrator","email":"admin@example.com"},"added":[],"modified":[],"removed":["src/org/devops/build.groovy"]}],"total_commits_count":3,"push_options":{},"repository":{"name":"demo-maven-service","url":"git@39.105.58.61:root/demo-maven-service.git","description":"","homepage":"http://39.105.58.61:9999/root/demo-maven-service","git_http_url":"http://39.105.58.61:9999/root/demo-maven-service.git","git_ssh_url":"git@39.105.58.61:root/demo-maven-service.git","visibility_level":0}}
4.4.2、jenkins配置
上面三个为报文中的变量。如果新建分支会生成"before":"0000000000000000000000000000000000000000"字段
过滤匹配说明
^push\s(?!0{40}).{40}\s(?!0{40}).{40}$
以push开头,且不等于40个0会被放开校验(也就是说新建分支的push请求会被校验住,其他的push请求会正常自动化触发构建)
$object_kind $after $before
4.4.3、参考链接
https://github.com/jenkinsci/generic-webhook-trigger-plugin/blob/master/src/test/resources/org/jenkinsci/plugins/gwt/bdd/gitlab/gitlab-push-ignore-when-no-commits.feature