当前位置:网站首页>Gerrit+2 triggers Jenkins task

Gerrit+2 triggers Jenkins task

2022-06-12 17:06:00 @TangXin

1.Linux Create secret key

cd /var/lib/jenkins

without .ssh Catalog , Manual creation required
mkdir .ssh

Create secret key
ssh-keygen -m PEM -t rsa -C “[email protected]” -f /var/lib/jenkins/.ssh/id-rsa

Modify the permissions
chmod -R 777 .ssh

2.Gerrit Create user

Gerrit establish zhangsan user
[[email protected] /]# htpasswd -m /gerrit.password zhangsan

Use zhangsan user Sign in Gerrit Set up SSH Keys
The contents to be filled in are /var/lib/jenkins/.ssh/id-rsa.pub What's in it

HTTP Credentials,CREATE NEW PASSWORD, The secret key here is very useful , Keep in mind
SL1rsmf6WIcvnYqEgHhajS2cZL+IqrLLEJQ8OA2dJg

Authorized user zhangsan Yes test1 The project has permission

3.Jenkins To configure Gerrit Trigger

Gerrit Trigger – Add New Server –
 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here

4.Jenkins Create a project test_gerrit_sonarqube

4.1 General

Discard old builds
Strategy :Log Rotation
Days to keep building :180 # This item can be configured freely , No coercion
Keep the maximum number of builds :180 # This item can be configured freely , No coercion
 Insert picture description here

4.2 Source code management

Multiple SCMs
Git
Repositories
Repository URL: Fill in user zhangsan Corresponding HTTP Connection address :http://[email protected]:8080/a/test1
Credentials: Fill in zhangsan User and corresponding HTTP Secret key SL1rsmf6WIcvnYqEgHhajS2cZL+IqrLLEJQ8OA2dJg Create credentials for
Refspec: Fill in refs/changes/*:refs/changes/*
 Insert picture description here

Branches to build
Specify Branch ( If it is empty, it means any): Fill in $GERRIT_REFSPEC
Source code library browser :( Automatically )
 Insert picture description here

Additional Behaviours
Strategy for choosing what to build
Choosing strategy: Fill in Gerrit Trigger
Check out to subdirectories
Local subdirectories of the warehouse : Fill in ${WORKSPACE}/test , Namely Gerrit Code in the repository clone To the local storage path , If this is a fixed value , The code pulls the latest code every time , If it's a variable , Then the complete project code will be pulled every time the code is pulled , therefore , It is suggested that this is a fixed value , This will only pull new code each time
 Insert picture description here

Advanced cloning behavior
Choose Fetch tags
Timeout for clone and pull operations ( minute ): Fill in 60 , If the amount of project code is too large , Need to fill in , otherwise jenkins When the task is executed , Pull code timeout
 Insert picture description here

4.3 Build trigger

Gerrit event
Gerrit Trigger
Choose a Server: Fill in Jenkins Set up Gerrit Trigger name :Gerrit-2
 Insert picture description here

Trigger on: This option is Gerrit Trigger Jenkins The conditions of the task
Comment Added Verdict Category:Code Review
Value:2 Meaning is Gerrit +2 when , Trigger Jenkins Task execution , whenever +2 Execute once when , Other methods are not implemented
 Insert picture description here

Dynamic Trigger Configuration
Gerrit Project
Type: Plain # Choose
Pattern: test1 # Fill in the project name
Branches
Type:Path # If Pattern Select all branches **, Then... Must be selected here Path, Otherwise, it cannot be triggered Jenkins Task execution
Pattern:** # Indicates that all branches of the item are selected  Insert picture description here

4.4 Constructing environment

No modification

4.5 structure

ls -l ${WORKSPACE}/test

 Insert picture description here

4.6 Post-build operation

No modification

5. Project submission code

5.1 commit

 Insert picture description here

5.2 push

 Insert picture description here

5.3 Gerrit

 Insert picture description here
 Insert picture description here

There is no trigger at this time Jenkins Task execution , When in Gerrit Middle alignment code +2 operation
 Insert picture description here

Jenkins The mission will be carried out , You can click on the g34, Jump to Gerrit Submitted code display page
 Insert picture description here

When Jenkins After task execution ,Gerrit You can see the prompt message
 Insert picture description here

6. follow-up

The above steps are completed Jenkins and Gerrit The connection between the two tools .
If you want to do it later SonarQube scanning 、 Unit tests, etc , You can set it in the build or post build steps

原网站

版权声明
本文为[@TangXin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206121645542671.html