这应该是相当基本的,但当我研究时,我遇到了像Gerrit Trigrs之类的东西,这些东西对于做这样简单的事情来说似乎太复杂了。
我想在JobDSL脚本中执行类似以下操作:
pipelineJob('deploy-game') {
definition {
environmentVariables {
env('ENVIRONMENT', "${ENVIRONMENT}")
keepBuildVariables(true)
}
cpsScm {
scm {
git{
remote {
url('https://blabla.git')
credentials('gitlab-credentials')
}
branches('${gitlabsourcebranch}')
}
}
scriptPath('path/to/this.jenkinsfile')
}
triggers {
gitlabPush {
buildOnMergeRequestEvents(true)
if ($gitlabMergeRequestState == 'merged') // this part
}
}
}
}
字符串
或者,触发所有MR事件,然后在管道脚本中过滤掉:
pipeline {
agent none
environment {
ENVIRONMENT = "${ENVIRONMENT}"
}
triggers {
$gitlabMergeRequestState == 'merged' // this one
}
stages {
stage ('do-stuff') {
agent {
label 'agent'
}
steps {
sh 'some commands ...'
}
}
}
}
型
我该怎么做?
2条答案
按热度按时间yfjy0ee71#
这就是它应该是什么样子,我希望这就是你正在寻找的。
字符串
xv8emn3q2#
要在打开合并请求或向具有打开合并请求的分支进行推送时触发构建,请将以下内容添加到Jenkinsfile
字符串
有关更多“触发器”选项,请访问https://github.com/jenkinsci/gitlab-plugin#defined-variables
要只执行从合并请求触发的stage,可以检查是否设置了
gitlabMergeRequestId
。如果在when块中执行此操作(如下所示),则只有在设置了ID(这意味着它来自合并请求)的情况下才会执行stages。这个when块只会在它是master或develop分支,或者它是由合并请求触发的情况下执行stage型