I've a group of multibranch pipeline jobs generated with the following piece groovy script:
[
'repo1',
'repo2',
].each { service ->
multibranchPipelineJob(service) {
displayName(service)
branchSources {
git {
remote("git@gitlab.com:whatever/${service}.git")
credentialsId('gitlab-ssh-key')
}
}
orphanedItemStrategy {
discardOldItems {
daysToKeep(0)
numToKeep(30)
}
}
triggers {
periodic(5)
}
}
}
and in each repo a Jenkinsfile
that looks as follows:
#!/usr/bin/env groovy
properties([
gitLabConnection('ci@gitlab.com'),
pipelineTriggers([
[
$class : 'GitLabPushTrigger',
triggerOnPush : true,
triggerOnMergeRequest: true,
]
]),
disableConcurrentBuilds(),
overrideIndexTriggers(false)
])
node {
def sbtHome = tool name: 'sbt-0.13.15', type: 'org.jvnet.hudson.plugins.SbtPluginBuilder\$SbtInstallation'
stage('Checkout') {
checkout scm
}
stage('Build') {
sh "'${sbtHome}/bin/sbt' clean compile"
}
stage('Test') {
sh "'${sbtHome}/bin/sbt' test"
}
if (env.BRANCH_NAME == 'develop' || env.BRANCH_NAME == 'master') {
stage('Publish') {
sh "'${sbtHome}/bin/sbt' publish"
}
}
}
It all works correctly. The seeder project generates all the folders from the first script and all the branches for given repo are built correctly.
Unfortunately I've problems with triggering a build for any branch after commit + push has been made to gitlab.
I've jenkins configured correctly - I mean the gitlab plugin, there is a connection and it all works well.
I've also added a webhook on the gitlab side and it also runs correctly. After a test push is sent I receive 200 OK
from jenkins and I do see in logs that scanning the branches has started and detected the changes correctly. Unfortunately the build for the changed branch does not start. Here's an extract from branch scan log:
Checking branch ci
‘Jenkinsfile’ found
Met criteria
Changes detected: ci (a7b9ae2f930b0b10d52bb42f1ecf96a68bba4a30 → 39a4c1a65051d5e90079feec14ad22455a77c58e)
Did not schedule build for branch: ci
I'm 100% sure that this not a problem with communication between my jenkins instance and gitlab account. I see the webhook being triggered after push to gitlab, I see the request being send and branch scan being run. Changes are also detected but why on earth the job isn't started? I've also read the docs thoroughly and have it all configured correctly.
Jenkins version: 2.150.3
Gitlab version: 11.8.1-ee
I found this very useful Setup Example (Continuous Integration with Jenkins and GitLab) . Especially the part Source Code management:
And also:
Edit1
You could try the following for one multibranch pipeline:
ci
ci
Edit2
I could not find a suitable git-project to run and try to reproduce this behaviour. So if someone know a similar project and could share, please comment and I could do some more testing.
For Gitlab (requested a trial key, otherwise it will be a GitLab Community Edition):
For Jenkins:
Then "Integration" —> "Jenkins CI" in Gitlab as in this image:
Hope this can help you!
I believe you need to use
includes()
to specify pattern(s) identifying which branches will be included:You can specify a number of patterns, which can include wildcards. For example:
There is also a corresponding
excludes()
for even finer-grained control.Possibly you have configured Basic Branch Build Strategies to only include specific branches e.g. using Exact Name:
master
which would skip the branchci
from your example.Ensure that your Jenkins branch build configuration covers the branches that you are testing for. Also make sure that Suppress automatic SCM triggering option is not set.
Do note that settings on Organization or Folder level will influence the specific Project and Job settings, unless they are specifically overridden on lower level.
We were facing similar (not the same) issues with gitlab and Jenkins and the problem was related with the credentials.
In Jenkins, we created a new global Access token for GitLab (Jenkins Configuration -> Credentials -> System -> New Global access -> Define a gitlab token). That generates a Token that we added it to the Webhook, now the hook being something like:
I hope it helps