Background: DSL creates pipeline by default after each run, in our case, we cannot disable create pipeline due to it already exists. Because it might be a change in the jenkinsfile, which need to be reload to the job and requires a re-creation. After a while, (it never happens in my master pipeline, which does a event pull triggere by gitlab) the MR pipeline start to have strange behavior, e.g it does not get trigger by any MR (new one or old one but with new commits) It was very hard to identify what exactly is wrong, but from gitlab activity it shows the webhook did works and it got 200 return So must be something wrong in the jenkins side. One thing I noticed is, the property values (which are used as env variable for jenkins job) are gone it is not consistent or till now I cannot tell what combination cause this "disappear"
Workaround: I did report an issue in github on gitlab jenkins plugin, but now I think of it, it should not be something wrong with the plugin itself. so either it is the dsl part, or jenkins core. the workaround I find (so far it does help) is to move these env variable as properties from dsl which generates it in jenkins config to jenkinsfile itself. Because jenkisnfile has no problem to load pure text.
this is a snippet for the changes:
if (pipelineconf.type != "MR-k8s-service") {
environmentVariables {
env('project', pipelineconf.project)
env('type', pipelineconf.type)
env('component', pipelineconf.component)
env('application', pipelineconf.application)
env('repo', pipelineconf.repo)
}
}
//MR
def mrspecialworkflowType(name, application, repo, ctlType) {
def temp = File.createTempFile('MRPL', '.groovy', new File("${WORKSPACE}/dsl/pipelineplugin"))
temp.write((new File("${WORKSPACE}/dsl/pipelineplugin/mrhead-Docker-workflow.groovy")).text)
temp.append("""withEnv([
'type=MR-k8s-service',
'noTag=true',
'ctlType=${ctlType}',
'component=${name}',
'application=${application}',
'repo=${repo}'
])"""
)
temp.append((new File("${WORKSPACE}/dsl/pipelineplugin/mr-Docker-workflow.groovy")).text)
return "dsl/pipelineplugin"+temp.absolutePath.substring(temp.absolutePath.lastIndexOf(File.separator))
}