I have a following Jenkins Job definition:
- scm:
name: some-project
scm:
- git:
url: git@gitlab.****/some-project.git
credentials-id: some-ssh-username-with-private-key
branches:
- origin/master
- project:
name: some-project
jobs:
- '{name}':
triggers:
gitlab:
trigger-push: true
trigger-merge-request: false
trigger-open-merge-request-push: never
Now this job can be uploaded to Jenkins without error but if I go to Configure
page of some-project
in Jenkins Web UI, I can see that Build when a change is pushed to GitLab
in Triggers section is not enabled. GitLab repo gets configured correctly - Source Code Management section of this job has git@gitlab.****/some-project.git
with some-ssh-username-with-private-key
credentials and branch origin/master
configured. But without working triggers this is useless.
What am I doing wrong?
Please note that I'm not asking how to configure GitLab WebHooks to trigger Jenkins job. I can do this manually and it works fine. But we want to manage our Jenkins jobs with Jenkins Job builder to avoid error prone process of configuring them via Web UI and to keep track of changes in job configuration - we are creating git repository with Jenkins job definitions.
I suspect you may need to put the triggers
in the job
itself, rather than under /project/jobs
.
With the triggers under the project
key, I experience the same symptom you do.
None of my triggers get created in Jenkins. Moving the triggers
section into a job
fixes the problem for me.
This yaml will build a jenkins job called builder-test
with the "Build when a change is pushed to GitLab" box checked:
- scm:
name: gitlab
scm:
- git:
url: https://gitlab.com/user/repo-name.git
branches:
- origin/master
- job:
name: builder-test
project-type: freestyle
description: "builder-test desc"
scm:
- gitlab
triggers:
- gitlab:
trigger-push: true
- project:
name: builder-test-project
jobs:
- 'builder-test'
Tested on Jenkins 2.32.3 using GitLab plugin 1.5.1 and JJB 1.6.2