CI/CD - 环境搭建(2) - Webhook实现Jenkins Job自动运行

Goal

When Github have commit,will trigger Jenkins job run automatically。

Prerequisites

Note: GitHub would not know how to contact “localhost” or 127.0.0.1: what GitHub would consider “local” is not your local machine.

Use Ngrok to expose our local host to the Internet.

  1. Download ngrok
  2. Config and run
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    [root@Automation src]# ./ngrok authtoken 3rsqkJTsPKW432XeLzEZ2_2uVdSyDqgLsTuSSb7FhaH
    Authtoken saved to configuration file: /root/.ngrok2/ngrok.yml
    [root@Automation src]# ./ngrok http 8080

    ngrok by @inconshreveable (Ctrl+C to quit)

    Session Status online
    Account yongfeiuall (Plan: Free)
    Version 2.2.8
    Region United States (us)
    Web Interface http://127.0.0.1:4040
    Forwarding http://5a6d5b8a.ngrok.io -> localhost:8080

    Forwarding https://v.ngrok.io -> localhost:8080

    Connections ttl opn rt1 rt5 p50 p90
    35 0 0.00 0.00 5.37 14.10

Create a Personal Access Token in GitHub


Copy the token

Set Up Jenkins Access to GitHub with Token

Add Token to Jenkins

Jenkins > Credentials

Config Access to Github

Jenkins > Manage Jenkins > Configure System

Config the Webhook

Jenkins does not automatically configure webhooks after config pipeline, need to run the job the first time.

In order to connect to Github, need to use the below format:
git credentialsId: 'xxxxxxxxxxxxx', url: 'https://github.com/yongfeiuall/artifactory-maven-example.git'

Then config this job again and save it without any updating, go to Github to check webhook in Repository setting page.

Check trigger automatically

Update script and commit to Github, Jenkins job run automatically

Download the ArtifactoryJenkins-0.0.1-SNAPSHOT.jar file, and extract source code, build successfully.

唐胡璐 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
分享创造价值,您的支持将鼓励我继续前行!