When contributing code to some open-source projectsgithub
Last submittedpull request
Or when the submitted branch code is updated,jenkins
The code is automatically executed.merge
When I ran the unit test, I read two words in my mind:NB!
At that time, I thought to myself, when I had to make such a big thing. Withgitlab
This idea is getting stronger and stronger as we gradually use it at work. I searched for Jenkins last weekend and found that Jenkins hasmerge request
Plug-in: gitlab merge request builder plugin
At that time, it was hard to remember, and began to look at the instructions for step-by-step configuration. The configuration is divided into two parts:
Part 1: Install plug-ins and basic settings
First install the plug-in. The Jenkins version must be later1.563
Fortunately, Jenkins is easy to upgrade.System Management
There is a big Upgrade button on the interface, and you can upgrade it1.570
.
InSystem Management
->Plugin Management
->Optional plug-ins
Found inGitlab Merge Request Builder
Install and restart Jenkins. The official documentation emphasizes the need.Restart Jenkins.
After restarting, enterSystem Management
->System settings
Inside, you can find moreGitlab Merge Request Builder
Configuration items
Gitlab Host URL
Enter the gitlab service address, suchhttp://192.168.0.1
Jenkins Username
Enter the Jenkins username in the project. Here, you need to create an account for Jenkins in gitlab, which is the same as that of other team members so that Jenkins can speak in the project.
Jenkins API Token
It is a permission Verification Code of Jenkins's account in getlab. This code can be entered after you log on to gitlab using the Jenkins accountAccount editing
InterfaceAccount
Tab, which is calledPrivate token
Crontab line
It mainly configures how often Jenkins checksmerge request
The default value is*/5 * * * *
That is, once every 5 minutes, but it is recommended to change JenkinsH/5 * * * *
It seems that the concurrency can be improved. I recommend*/5
ChangedH/5
It seems that no problem has been found so far.
Enable build triggered message
When the plug-in is activatedmerge request
The interface sends a message that Jenkins has started to work, but I feel that it is still useful for debugging. It is a bit cool to use normally.
Default success message
,Default unstable message
AndDefault failure message
The three configurations are a success message template and two failed message templates. The dry words are not clear, so you can add an emoji in the template, for example:smiley:
Or:broken_heart:
Ignore SSL Certificate Errors
Ignore as the name implieshttps
Certificate error. This option is useful for assuming gitlab private servers in the LAN!
Do not forget to clickSave
Button
Part 2: create a task
You can create a task at the beginning of the process. ClickNew
Create a new task and select the Task Type you need. Because I am a Maven project, I choseBuild a maven2/3 Project
, Fill inProject name
ClickOK
Go to the task details page
The official document says that if you installGitHub plugin
InGitHub Project
Enter your project in the columnGitlab
But I didn't install this plug-in, so I skipped it.
FindSource code management
Column and selectGit
, Starting from here
- Entered according to the general
Repository URL
AndCredentials
ClickAdvanced...
Button inName
Enterorigin
- To support
forked
Branch submittedmerge requests
You need to add another source. ClickAdd Repository
And thenRepository URL
Set content${gitlabSourceRepository}
,Credentials
Same as the primary source,Advanced...
InName
Set${gitlabSourceName}
- Find
Branch Specifier
, Change the content${gitlabSourceName}/${gitlabSourceBranch}
- Find
Additional Behaviours
Click to writeAdd
Drop-down list of words, selectMerge before build
- In
Merge before build
Block, SetName of repository
Isorigin
, SetBranch to merge to
Is${gitlabTargetBranch}
- There is a prompt in the official document to ensure that
Prune stale remote-tracking branches
Not added
FindBuild a trigger
Topic
- Set
Gitlab Merge Requests Builder
Check
- In
Gitlab Project Path
Enter the project path in the format similaryour_group/your_project
You can open your project's home page in git if you don't know how to configure the repository, and see the URL for reference.http://git.tld/your_group/your_project
Do not enter the whole URL.your_group/your_project
This part.
- The official document also mentions
Target Branch Regex
It seems to be an option that can act as a branch whitelist. If this parameter is not specified, allmerge request
Can trigger this task. But I don't know why I didn't find this option here, So I skipped it.
Here followmerge request
The configuration is complete, and other compilation options of the project are configured. For exampleGoals and options
Entered inclean test -U
In this way, the build is only executed to complete the test, so as to check its quality before merging the code.
Do not forget to click after all configurations are complete.Save
Button.
Now, all configurations are complete. Next, you can try to createmerge request
Let's see if it's easy.