“触发器之jenkins实现gitlab trigger”的版本间的差异
跳到导航
跳到搜索
第27行: | 第27行: | ||
Started by GitLab push by meimei | Started by GitLab push by meimei | ||
+ | </pre> | ||
+ | |||
+ | === 2024 新例子=== | ||
+ | <pre> | ||
+ | #少了在gitlab的配置而已 | ||
+ | pipeline { | ||
+ | agent any | ||
+ | stages { | ||
+ | stage("test") { | ||
+ | steps { | ||
+ | script { | ||
+ | |||
+ | println("${WebHookData}") | ||
+ | |||
+ | webHookData = readJSON text: "${WebHookData}" | ||
+ | |||
+ | env.srcUrl = webHookData["project"] ["git_http_url"] | ||
+ | env.branchName = webHookData["ref"] - "refs/heads/" | ||
+ | env.commitId = webHookData["checkout_sha"] | ||
+ | env.commitUser = webHookData["user_username"] | ||
+ | env.userEmail = webHookData["user_email"] | ||
+ | |||
+ | currentBuild.description = "Trigger by Gitlab \n branchName: ${env.branchName}" | ||
+ | currentBuild.displayName = "${env.commitId}" | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | } | ||
</pre> | </pre> | ||
2024年9月25日 (三) 15:39的最新版本
目录
触发器
jenkins pipeline 实现gitlab trigger
jenkins 上的配置
前提 得安装 gitlab git 两个 plugin ,Gitlab Hook Plugin已放弃 pipeline job 中的 构建触发器 默认的选中就行了 有个 Build when a change is pushed to GitLab. GitLab webhook URL: http://jenkins.com/project/core-manage 这个后面会用到 还有 右下的 高级 点开 -->Secret token >Generate 生成一个 key 记下来哦
gitlab上的配置
这种操作不用添加pipeline grovvy脚本 选中你的git源码项目 --左边下的 设置-->集成--> webhooks 网址填写网上jenkins上的那个url , secret 填写上面记下来的key
右下的 Project Hooks (2) 可以选择你的项目 test一下
最后回jenkins jobs看效果
只要有人提交一代码 就会build job 构建历史如下 #8 2021-12-2 下午3:13 Started by GitLab push by meimei
2024 新例子
#少了在gitlab的配置而已 pipeline { agent any stages { stage("test") { steps { script { println("${WebHookData}") webHookData = readJSON text: "${WebHookData}" env.srcUrl = webHookData["project"] ["git_http_url"] env.branchName = webHookData["ref"] - "refs/heads/" env.commitId = webHookData["checkout_sha"] env.commitUser = webHookData["user_username"] env.userEmail = webHookData["user_email"] currentBuild.description = "Trigger by Gitlab \n branchName: ${env.branchName}" currentBuild.displayName = "${env.commitId}" } } } } }
other grigger
Jenkins parameters trigger pipeline plugin 一个pipeline触发另外pipeline并传递参数