jenkins配置
- 安装Generic Webhook Trigger
- 配置远程触发令牌
勾选Print post content和Print contributed variables用于打印值
配置gitlab
- 选择新增webhook
配置webhook
http://JENKINS_URL/generic-webhook-trigger/invoke,将JENKINS_URL修改成自己的jenkins地址
- 先保存再测试
解析jenkins接收到的事件json里边的参数
jenkins配置
流水线配置方法
#!groovy
/*
演示mvn集成到jenkins 流水线中的用法
*/
string buildShell = "$BUILD_SHELL"
pipeline{
agent {
node {label "$CI_NODE"}
}
stages{
stage("mvn build"){
steps{
if ("${runOpts}" == "GitlabPush"){
env.runOpts = "GitlabPush"
branch = branch - "refs/heads/"
currentBuild.description = "Trigger by ${url} ${branch}"
}
script{
mvnHome = tool "MVN"
sh "$mvnHome/bin/mvn ${buildShell}"
}
}
}
stage("gradle build"){
steps{
script{
gradleHome = tool "GRADLE"
sh "$gradleHome/bin/gradle ${buildShell}"
}
}
}
stage("ant build"){
steps{
script{
antHome = tool "ANT"
sh "$antHome/bin/ant ${buildShell}"
}
}
}
}
}
参数解析效果:
参考文档;https://www.cnblogs.com/louis2008/p/jenkins-gitlab.html
视频:https://www.bilibili.com/video/BV11P4y1m7nG?p=19&vd_source=9bfdc5be7a49dd0810a8319a82a055d3