The DevOps case is designed to help users better use DevOps in practice.
Problem Description
Jenkins2.0 Pipeline framework iPipeline (ie, the pll library) set MergeCI trigger condition to Change merged mode and fixed, ie, need to go by the code walker +2, and then click on the Submit button by the Core member to push the code Stored, and then trigger the MergeCI process, the process of the VerifyCI and MergeCI process as shown below:
Combined with the above figure, we can find that there is a problem: Once the code walks through (+2 points), and then the Core member passes (Submit), the code is immediately put into the library, and then the MergeCI process is triggered. If MergeCI runs at this time, an error occurs. That error has been put in at this time and it affects subsequent developers to incorporate the code.
Combined with the actual characteristics of the development of this project agreement, it is highly possible that the MergeCI passed by VerifyCI will interact with others. This may result in errors in the main branch code and the interaction among developers, ultimately affecting the code submission and integration. effectiveness.
Based on this situation, we propose a model where MergeCI is triggered by +2 points on Gerrit by code reviewers. Only when MergeCI runs, the code will be pushed into the library. The most immediate benefit is that the code on the backbone branch is always correct, and it will not affect other people's code due to MergeCI's error, and the other advantage of this method is that there is no need to set a key role to be responsible for the submission of Submit code. What is needed is to walk through the code, which also increases the degree of automation and saves manpower. The process can be illustrated as follows:
Therefore, the Merge CI setting of the pllll library does not satisfy this project, so we decided to expand the plll library support for MergeCI operation mode.
Optimization practice
By overloading the property setting function of the PLLL library, the setting of different triggering conditions of MergeCI according to the CI type is added:
/**
* Tool Name: set_default_properties
* Tool Description: Set the default parameters
* Parameter Description:
* - citype : CI type
* - args : parameter list
**/
Def set_default_properties(citype, args){
Def buildParameters =[]
Def buildTriggers =[]
Set_parameters_properties(buildParameters, args)
Set_cron_properties(buildTriggers, args)
Set_gerrit_properties(citype, buildParameters, buildTriggers, args)
/* --------Parameters------- */
Properties([
[$class:'GitLabConnectionProperty', gitLabConnection:''],
[$class:'RebuildSettings', autoRebuild:false, rebuildDisabled:false],
buildDiscarder(logRotator(artifactDaysToKeepStr:'', artifactNumToKeepStr:'', daysToKeepStr:'14', numToKeepStr:'100')),
Parameters(buildParameters),
pipelineTriggers(buildTriggers)
])
/* Clear temporary variables */
buildParameters=null
buildTriggers=null
Return
}
/**
* Function name: set gerrit attribute
**/
Def set_gerrit_properties(citype, buildParameters, buildTriggers, args)
{
// ...where the code is omitted...
If("verifyci"=="${citype}"){
gerritEvents =[
patchsetCreated(
excludeDrafts:false,
excludeNoCodeChange:true,
excludeTrivialRebase:false
),
draftPublished()
]
// If the CI type is MergeCI, the setter trigger condition is Code-Review +2 to trigger
}elseif("mergeci"=="${citype}"){
gerritEvents =[
commentAdded(commentAddedTriggerApprovalValue:'+2', verdictCategory:'Code-Review')
]
}
// ...where the code is omitted...
}
It can be seen from the code that in the set_gerrit_properties function, a special judgment is made. If it is MergeCI, the trigger condition is set to Code-Review +2 alone, so that the demand can be satisfied.
Use example:
In MergeCI's Jenkinsfile, call plll.set_default_properties to explicitly specify the mergeci type when setting the project properties. Set the default attribute parameters in the Jenkinsfile code of this project as an example:
Def set_default_properties(){
Plll.set_default_properties("mergeci",[
/* Association gerrit */
Gerrit:[
Server:"${env.GERRIT_SERVER_NAME}",
Projects:[[project:"${env.GERRIT_PROJECT}", branch:"${plll.getJobBaseName()}"]]
],
/* Custom parameters */
Parameters:[
Choice(choices:'yesno', description:'Empty Build Environment', name:'CLEAN_ALL'),
String(defaultValue:"${plll.getJobBaseName()}", description:'trigger branch', name:'BRANCH_TAG')
],
]);
}
In addition, you need to configure the Gerrit Trigger settings in MergeCI in Jenkins System Management as shown below:
Analysis of advantages and disadvantages
1. Advantages
Developers are independent of each other, other people's wrong code can not be stored, does not affect others
The main branch code is always correct, does not affect other people pull code verification and normal integration code
No need for sub-core members to submit operation, once the MergeCI is running correctly, the code will be automatically stored
2. Disadvantages
The principle determines that it cannot be parallelized, so it needs to be considered according to different project conditions. However, from the perspective of the actual practice of the project, VerifyCI of the project supports concurrent execution of several tasks simultaneously, and MergeCI queues execution. However, because MergeCI performs faster and there are few conflicts, MergeCI's code can smoothly integrate one by one. In addition, happiness has greatly improved over the past.
Plastic USB Flash Disk adopts advanced harmless ABS plastic, environmental protection and safety. Plastic USB flash disk has a variety of styles, among which the thickness of the card type plastic U disk is only 2mm, the same size as the bank card, which can be directly put into the wallet, convenient to carry, not easy to lose. In addition, we provide deep customization, high-definition printing, to create exclusive enterprise USB drive.
Plastic Usb Flash Disk,Usb Flash Pen Drive,Plastic Usb Key,Usb Flash Drive Storage, Jump Drive
MICROBITS TECHNOLOGY LIMITED , https://www.hkmicrobits.com