Openshift 3.5: Using GitHub Webhook to trigger new build

One awesome features of openshift is the webhook triggered-build. A GitHub webhook can notify Openshift if there are any code changes pushed to the repository.
To get the webhook, describe the build config:
[root@master ~]# oc get bc
NAME            TYPE      FROM         LATEST
my-own-django   Source    Git@master   2

[root@master ~]# oc describe  bc/my-own-django 
Name:           my-own-django
Namespace:      djangoex
Created:        22 minutes ago
Labels:         app=my-own-django
Annotations:    openshift.io/generated-by=OpenShiftWebConsole
Latest Version: 2

Strategy:       Source
URL:            https://github.com/aizuddin85/django-ex.git
Ref:            master
From Image:     ImageStreamTag openshift/python:3.5
Output to:      ImageStreamTag my-own-django:latest

Build Run Policy:       Serial
Triggered by:           ImageChange, Config
Webhook Generic:
        URL:            https://master:8443/oapi/v1/namespaces/djangoex/buildconfigs/my-own-django/webhooks/8435c468d0d7a6fe/generic
        AllowEnv:       false
Webhook GitHub:
        URL:    https://master:8443/oapi/v1/namespaces/djangoex/buildconfigs/my-own-django/webhooks/fc8b1494a5993b04/github

Build                   Status          Duration        Creation Time
my-own-django-2         complete        2m25s           2017-09-20 08:29:57 +0000 UTC
my-own-django-1         complete        2m43s           2017-09-20 08:21:59 +0000 UTC

No events.

Note the URL under Webhook GitHub. Copy the URL and configure the GitHub project to use the webhook.
Webhook GitHub:
        URL:    https://master:8443/oapi/v1/namespaces/djangoex/buildconfigs/my-own-django/webhooks/fc8b1494a5993b04/github

Go to the above page on GitHub under settings. Click Edit and then paste the URL into Payload URL and then Update webhook.
Note that during the describe bc you can see that the project was created using source strategy with the GitHub URL https://github.com/aizuddin85/django-ex.git with master branch.
Now we are going to clone the project to make some amendments. So the GitHub will notify Openshift for new build.
[root@master ~]# git clone https://github.com/aizuddin85/django-ex.git
Cloning into 'django-ex'...
remote: Counting objects: 755, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 755 (delta 3), reused 11 (delta 3), pack-reused 743
Receiving objects: 100% (755/755), 212.53 KiB | 0 bytes/s, done.
Resolving deltas: 100% (331/331), done.
In the project dir, replace django-ex/welcome/templates/welcome/index.html with django-ex/welcome/templates/welcome/index.html.mod
[root@master ~]# cd django-ex
[root@master django-ex]# cp welcome/templates/welcome/index.html.mod welcome/templates/welcome/index.html
cp: overwrite ‘welcome/templates/welcome/index.html’? yes
[root@master django-ex]# 
Now commit the change and push to repo.
[root@master django-ex]# git commit -am 'test commit'
[master 671546a] test commit
 Committer: root <root@master.c.openshift-179205.internal>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+), 1 deletion(-)
[root@master django-ex]# git push origin master
Password for 'https://aizuddin85@github.com': 
Counting objects: 11, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 501 bytes | 0 bytes/s, done.
Total 6 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
To https://aizuddin85@github.com/aizuddin85/django-ex.git
   6186717..671546a  master -> master
[root@master django-ex]# 
At this moment you can see the build config is having new build.
[root@master django-ex]# oc describe bc my-own-django
Name:           my-own-django
Namespace:      djangoex
Created:        36 minutes ago
Labels:         app=my-own-django
Annotations:    openshift.io/generated-by=OpenShiftWebConsole
Latest Version: 3
Strategy:       Source
URL:            https://github.com/aizuddin85/django-ex.git
Ref:            master
From Image:     ImageStreamTag openshift/python:3.5
Output to:      ImageStreamTag my-own-django:latest
Build Run Policy:       Serial
Triggered by:           ImageChange, Config
Webhook Generic:
        URL:            https://master:8443/oapi/v1/namespaces/djangoex/buildconfigs/my-own-django/webhooks/8435c468d0d7a6fe/generic
        AllowEnv:       false
Webhook GitHub:
        URL:    https://master:8443/oapi/v1/namespaces/djangoex/buildconfigs/my-own-django/webhooks/fc8b1494a5993b04/github
Build                   Status          Duration                Creation Time
my-own-django-3         running         running for 14s         2017-09-20 08:58:19 +0000 UTC
my-own-django-2         complete        2m25s                   2017-09-20 08:29:57 +0000 UTC
my-own-django-1         complete        2m43s                   2017-09-20 08:21:59 +0000 UTC
No events.
In the GitHub WebHook setting page, click Edit you can see the payload being sent.

Comments

Popular Posts