Jenkins Settings Gitlab Web hooks

Source: Internet
Author: User

Background

Interface automation expects code push to trigger implementation of continuous integration after code push, automating the execution of Jenkins's job.

Step Preparation work

Tool: Jenkins,gitlab

Jenkins needs to install plugins: git plugin,gitlab hook plugin, Gitlab plugin (some plugins are self-contained, missing what to install)

Gitlab: Make sure you have Web hook permissions, this is related to the company's Gitlab, and the Web hooks under Portal settings are as follows:

Ensuring connectivity between Gitlab and Jenkins

The approximate principle of hook is actually very simple: after setting up the web hooks, when the GIT project triggers the event, it sends a POST request to the hooks URL you filled out.

So first, make sure the connectivity of the Gitlab and Jenkins servers

My side is in Jenkins. The server writes a test interface through the Flask framework:

 fromFlaskImportFlask,requestapp= Flask (__name__) @app. Route ("/test", methods=['GET','POST'])defHello ():#return "Hello world!"        Print(Request.data); returnRequest.dataif __name__=="__main__": App.run (Host='0.0.0.0', debug=true,port=8080)

Then accessing Http://your-jenkins-server-ip:8080/test via post will return the body data of your request.

Set the URL of the web hooks to http://your-jenkins-server-ip:8080/test after saving,

Click on "Test Hook" testing whether the hook is in effect, normal, page tip 200

Set up Jenkins

Source Management settings

Build trigger Settings, This URL is the URL that needs to be filled in Gitlab web hook

After setting up, click Save

Setting up a web hook for Gitlab

URL to fill in the URL on Jenkins, here's the Http://your-jenkins-server-ip:port/project/smart

Whether the test takes effect

Update the code on the Gitlab and commit;

Go to Jenkins to see if the job is executed:

Summary

1. Need to clarify the principle, is Gitlab access to set the hook URL;

2. When the setup of Jenkins and Gitlab is not a problem, but the test hook is not passed, you need to think about why this situation? So the suspicion is the company Gitlab and self-built Jenkins network does not pass;

3. After looking for a security colleague to help with the configuration, or not (suspect life), think about how you can quickly verify the network or not pass it? So try to write a simple interface verification yourself;

Jenkins Settings Gitlab Web hooks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.