This is the 19th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021″
❤️ About the author: Hello everyone, I am Xiao Xu Zhu. Java field quality creator 🏆, CSDN blog expert certification 🏆, Huawei Cloud enjoy expert certification 🏆
❤️ technology live, the appreciation
❤️ like 👍 collect ⭐ look again, form a habit
A fan asked me if I could automate Jenkins deployment once GitLab submits. Take the time to post a good code, share with my fans, but also share with everyone.
Environment to prepare
Jenkins installation:
0❤️Jenkins from zero to one ❤️ : Install – Windows install using Jenkins. Msi
Install gitlab:
Gitlab from Zero to One is installed based on Docker-Gitlab
Jenkins configuration
Installing a plug-in
Install Gitlab Hook plug-in
Install the Build Authorization Token Root plug-in
Install Generic Webhook Trigger
Install GitLab
After the plug-in is installed successfully, restart Jenkins.
Gitlab configuration
Create a new test project
Create a simple Spring Boot project
After startup, access effects
Jenkins created a ci-test project
Operation as shown in figure:
Discard old builds
Choose Git for source management
Select the corresponding account password and specify the branch
Failed to connect to repository : Error performing git command: Git. Exe ls – remote – h http://192.168.88.131:9980/root/ci_test.git HEAD
Error: The version of Git is too low, you need to upgrade it, or Jenkins has not configured git.
Next, log on to Jenkins screen and open “System Administration” -> “Global Tool Configuration” -> “Git” -> “Path to Git executable”
After saving, go back to the project configuration and reconfigure git information
There is no error at this point
Build triggers and add Webhooks
You need to install the Generic Webhook Trigger and GitLab plug-ins to get this option
Remember to fill in the GitLab CI Service URL in GitLab webhooks
Gitlab configuration webhooks
Fill in the URL and token (because I did not do SSH authentication, SO I did not use SSL authentication)
URL: Jenkins URL configured above
An error is reported after saving
Urlis blocked: Requests to the local network are not allowed
Solution:
Enter the admin area
Test whether webhook is successful
An error was reported after operation
Hook executed successfully but returned HTTP 403 Error 403 anonymous is missing the Job/Build permission
HTTP ERROR 403 anonymous is missing the Job/Build permission
URI: /project/ci_test STATUS: 403 MESSAGE: anonymous is missing the Job/Build permission SERVLET: Stapler
Powered by Jetty: / / 9.4.42 v20210604
Solution:
The anonymous user has the read permission
Remove cross-site request forgery
Major changes in Jenkins release since 2.204.6 include: removal of CSRF protection disabling
Jenkins version 2.204.6:
Jenkins 2.204.6 and above:
CSRF can be shut down after Jenkins is started by adding relevant parameter configuration for canceling protection before Jenkins starts. The configuration is as follows:
-Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true
Copy the code
Restart Jenkins and see the effect, as shown in the figure, that is, CSRF is turned off.
If you hit test and return 200, you’re successful.
Validate automated builds
Submit the code to GitLab
Added an interface
Push to gitlab
Jenkins view
As shown, it has been built automatically
Let’s look at the log
reference
To solve the “Hook executed successfully but returned HTTP 403” problem: blog.csdn.net/anqixiang/a…
High version Jenkins closed cross-site request forgery (CSRF) protection: www.cnblogs.com/kazihuo/p/1…