jenkins gitlab webhook 403 anonymous is missing the Job/Build permission 解决
gitlab触发jenkins webhook时候报错:
jenkins gitlab webhook 403 anonymous is missing the Job/Build permission
首先jenkins 某个pipeline 的webhook是有权限控制,并不是任意gitlab中的项目都可以触发。
而控制的途径就是通过secret token。
而且gitlab的触发pipeline的过程完全可以写到Jenkinsfile里。
例如:
triggers {
gitlab(
triggerOnPush: true,
triggerOnMergeRequest: true,
branchFilterType: 'NameBasedFilter',
includeBranchesSpec : 'master',
secretToken: "abcde5432167890888"
)
}
这样配置后,默认的给pipeline设置好了 secret token。
然后在gitlab中配置pipeline的webhook及secret token,如图:
最后测试一下webhook:
显示:
代表webhook成功。
-——————————————————————————————————————————————
需要注意的是:
1.jenkins创建pipeline后,需要手动构建一次,使其第一次加载到gitlab上Jenkinsfile
2.pipeline定义时,脚本的名称固定为 “Jenkinsfile”
测试改成别的名字的话,secret token未能生效。这就是jenkins gitlab webhook 403 anonymous is missing the Job/Build permission产生报错的原因。
如果生效的话,可以在pipeline的配置中看到secret token的值被回显出来:
如果没有回显,gitlab调用pipeline的webhook肯定就是403了~~~~
还没有评论,来说两句吧...