Webhook for Jenkins and github

One of the functions to link GitHub and Jenkins is called “Webhook”. By using this Webhook, you can run Jenkins’ jobs when pushing a branch to the repository managed on GitHub, when creating a new Pull Request, and so on.

There are three main ways to link Jenkins with GitHub and Webhook by the following three methods.

Jenkins Standard Webhook
– Set up “build for remote” provided as standard function of Jenkins
Git Plugin
– A plugin that can provide functions that can clone and execute git repositories when building Jenkins GitHub Plugin.
Plug-in to receive push event from GitHub
– Jenkins can automatically register Webhook to GitHub

Jenkins Standard Webhook
Build and trigger

Continue to configure Webhook with GitHub. From the repository page you can add it from Setting > Webhooks > Add Webhook.

Go to Github repository

See webhooks and add webhook

「Jenkinsの管理」>「ユーザーの管理」>「(API Token を取得したいユーザーID)」>「設定」>「APIトークンの表示」

Payload URL

Oh, Ok.
close jenkins
[vagrant@localhost app]$ sudo service jenkins stop
Shutting down Jenkins [ OK ]

Jenkins setting and how to use it?

Job describes a series of operations that Jenkins wants to run. If you think that is something like batch files or Linux shell script now.

1. put name for Enter an item and press free style project build

2. Next page, chose build and set shell execution

3. write shell script

echo 'hello jenkins'

4. save task and run build

console output

ビルドします。 ワークスペース: /var/lib/jenkins/workspace/HelloJenkins
[HelloJenkins] $ /bin/sh -xe /tmp/jenkins6861841405666017940.sh
+ echo ‘hello jenkins’
hello jenkins
Finished: SUCCESS

Wow, Perhaps it’s fun to play.

install Jenkins into CentOS

First make sure java is installed
[vagrant@localhost app]$ java -version
openjdk version “1.8.0_191”
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

Add jenkins repository
[vagrant@localhost app]$ sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
–2019-01-22 21:14:32– http://pkg.jenkins-ci.org/redhat/jenkins.repo
pkg.jenkins-ci.org をDNSに問いあわせています…
pkg.jenkins-ci.org||:80 に接続しています… 接続しました。
HTTP による接続要求を送信しました、応答を待っています… 200 OK
長さ: 71
`/etc/yum.repos.d/jenkins.repo’ に保存中

100%[======================================>] 71 –.-K/s 時間 0s

2019-01-22 21:14:36 (3.39 MB/s) – `/etc/yum.repos.d/jenkins.repo’ へ保存完了 [71/71]

[vagrant@localhost app]$ sudo rpm –import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key

install jenkins
[vagrant@localhost app]$ sudo yum install -y jenkins

[vagrant@localhost app]$ sudo service jenkins start
Starting Jenkins [ OK ]