If your repository is not public generate a new deploy token:
- Go to Settings >> Repository >> Deploy Tokens
- Generate a new Deploy Token. You get an
username
and adeploy_token
Jenkins version tested: (ver. 2.235.2)
- Go to settings of a project
- Activate "this build has parameters" and create a parameter
BRANCH
, set the default value to a branch - In "Source code management" set GIT
- In "Repository URL" set the url of repository. Example:
https://<username>:<deploy_token>@gitlab.example.com/tanuki/awesome_project.git
- In "Branch Specifier (blank for 'any')" set the parameter created:
$BRANCH
- In "Additional Behaviours" add "Advanced sub-modules behaviours"
- If you want, select the behaviors. I selected:
- Recursively update submodules
- Update tracking submodules to tip of branch
Jenkins version tested: (ver. 2.235.2)
- Go to settings of a project
- Go to "build trigger"
- Enable "Build when a change is pushed to GitLab. GitLab webhook URL: <...>" (keep the url webhook)
- In "Enabled GitLab triggers" select the events you want (i want only "Push Events" so disable all others options)
- Click in advanced
- Generate the secret token (keep secret token)
- Save
- Go to Settings >> Integrations
- Past the project url from Jenkins
- Past the secret token seted in Jenkins
- In push events set the branch name if you want
- Disable "Enable SSL verification" if you want
- Save clicking in "Add webhook"