Jenkins GoGS integration with webhook

Please use deployment from this article to install and configure full topology which we need.

In the ‘git bash‘ generate some ssh keys which will be used from Jenkins to the GoGS. Copy public key and add this key in the GoGS.

$ ssh-keygen -b 2048 -t rsa -f gogs -q -N ""
$ cat gogs.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCg8o5mTDO/5EmL5uiMi1UFB+yTVuSPJkZXIKFuKTKYBAZSwTFEPUG3RYmvrTo0PUf14ocNj2EccuHEz2Bz0XVisHDPdp3bEcD7RoR+EKyVKHLZ2vL1QVUiBe9nywbPu0VWL9x1Dy05P8weuqQqnuTMtGXGjcUf97km4CiX+5wUG6++4da5G/VfaeM09QZ6xbpwmZXyvpLV0CuhyzBjxzH6RArYAncyF5jeWlKCWkM42OjW+S7Ch9oO86K8LCE8ksOW5u6gfAiFG5bFy7XZZirnF8wT2NZatCgbWpFtfnxCZDJIXm3m4qDfT/+eASIM9nn4yphjdlXpBpkhoJ4dXBB9 User@DESKTOP-SHSRIMD

Install ‘GoGS plugin‘ in the Jenkins. Go to the Main menu -> Manage Jenkins -> Manage Plugins -> Go to the Available tab -> In the search filter enter ‘Gogs Plugin‘ -> Select checkbox and press ‘Download now and install after restart‘ button
gogs-plugin.png

Add new ‘SSH Username with private key‘ credential which will be used to clone codes from GoGS. Enter directly private key which generated before
add-ssh-key-for-gogs

Add new ‘Freestyle project‘ to test gogs. Go to Jenkins main menu -> New Item -> enter name ‘Jenkins-GoGS-Trig‘ -> Press OK button
gogs-frees-proj

Under ‘General‘ tab select checkbox ‘Use Gogs secret
select-gogs-secret

Generate some random password(This is will be used as API token between GoGS and Jenkins. Copy this secret in some secure place because we will need this in GoGS configuration) and paste inside of ‘secret‘ line
input-gogssecret

Under ‘Source Code Management‘ press ‘Git‘ enter GoGS repository URL (git@192.168.106.232:gogs/jenkins-gogs.git) which will be created, select Credential for git and press ‘Apply‘ button
select-gogs-ssh-key

To clean workspace before each build, just select checkbox ‘Delete workspace before build starts‘ under ‘Build Environment
delete-workspace

At the end of page in the ‘Build‘ section press ‘Add build step‘, select ‘Execute shell‘ then add ‘cat README.md‘ command (it will print all lines which came from gogs repository) to check trigger and press ‘Save‘ button
add-execute-shell
add-execute-shell1

In the GoGS interface create new repository. Press plus button (username: gogs and password: gogspassword from gogs-provision.sh script in the git repository):
gogs-interface

Enter name, repo will be private and press ‘Create Repository‘ button.
create-gogs-repo

Clone this repository and add some file. Disable SSC checking.

$ git config --global http.sslVerify false
$ git clone https://192.168.106.232/gogs/jenkins-gogs.git
Cloning into 'jenkins-gogs'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
$ cd jenkins-gogs/
$ echo 'Added README' > README.md
$ git add README.md
$ git commit -m "Added README"
$ git push

Under your profile press ‘Your Settings‘ button
gogs-profile-settings

Then press ‘SSH Keys‘ and then ‘Add Key
add-gogs-sshkey

Add public key which created before and press ‘Add Key‘ button
input-private-sshkey

Then go to the Settings -> Webhooks -> Add Webhook
press-webhook-button

Select ‘Gogs
press-gogs-wbbutton

In the opened page we will configure GoGS to send information to the Jenkins. In the Payload URL add line as following syntax
http://JenkinsIPAddress:Port/gogs-webhook/?job=JobNameInTheJenkins

In the secret line add before generated random password for API which used in Jenkins. Select event types for your need and then press ‘Add Webhook‘ button
gogs-add-webhook

In the opened page press to edit button:
press-webhok-edit

Then press to the ‘Test Delivery‘ button and look at the Recent Deliveries
test-gogs-webhook

Add some line to readme and push to check result:

$ echo "This line will be printed in the Jenkins build output to see the reult" > README.md
$ git add README.md
$ git commit -m "Added check jenkins"
$ git push

At the same time go to check Jenkins side. As we see the trigger is worked.
jenkins-gogs-outut

Look at the line which printed from README.md file:
jenkins-gos-comes-line

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s