14/01/2017 - GIT, JENKINS, LINUX
Bu örneğimizde, Jenkins sunucu ile aşağıdaki listelenen olaylara göre testleri çalıştıracağız. İki tane Jenkins item/projemiz olacak. Birincisi Nation-PullRequest sadece normal pull request olayları (create, push, comment, close ve reopen) için testleri çalıştıracak. İkinci ise Nation-Merge sadece pull request merge için testleri çalıştıracak.
/var/lib/jenkins/workspace/Nation-PullRequest/ veya /var/lib/jenkins/workspace/Nation-Merge/ klasörüne kopyalar.Nation-PullRequest için geçerlidir.Jenkins'in testleri çalıştırdığı zamanlar:
test this please, add to whitelist vs.) yorum olarak yazdığında.Nation-Merge için geçerlidir.14.042.4.71.9.12.32.1Nation-PullRequest.Nation-Merge.Nation-PullRequest.Nation-Merge.Projemizin ismi nation ve özellikleri de aşağıdaki gibidir.
Browser URL: https://github.com/Inanzzz/nation
Clone URL: https://github.com/Inanzzz/nation.git
Kurulumu yaptığınızı ve sistemin çalıştığını varsayıyorum.
Kurulumu yaptığınızı ve http://localhost adresinin ulaşıma açık olduğunu varsayıyorum.
$ sudo apt-get update
$ sudo apt-get install git
$ git config --global user.name "Inanzzz"
$ git config --global user.email "inanzzz@helloworld.com"
$ git --version
git version 1.9.1
Konuyla ilgili tam bilgiyi buradan bulabilirsiniz.
Java JDK ve JRE yükleme işlemini yapın. Bu yazıyı yazarken openjdk-7-jre ve openjdk-7-jdk tavsiye ediliyordu.
$ sudo apt-get install openjdk-7-jre
$ sudo apt-get install openjdk-7-jdk
$ java -version
java version "1.7.0_121"
OpenJDK Runtime Environment (IcedTea 2.6.8) (7u121-2.6.8-1ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.121-b00, mixed mode)
$ wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
$ sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
$ sudo apt-get update
$ sudo apt-get install jenkins
$ sudo service jenkins status
Jenkins Continuous Integration Server is running with the pid 11444
Log dosyası: var/log/jenkins/jenkins.log
http://localhost:8080 adresine gidin.$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword komutunu çalıştırın.admin:ab56a379e3154a38acfc46b91bc0c25a (şifreyi yukarıdaki komut ile bulmuştunuz) kullanabilirsiniz.http://localhost:8080 adresine gidin.$ sudo service jenkins restart ile yeniden başlatın.http://localhost:8080 adresine gidin.http://12345e55.ngrok.io/ yazdım. Eğer yazmasaydım:Inanzzz'yi "Admin list" textbox'una ekleyin.http://localhost:8080 adresine gidin.http://your-jenkins-domain.com:8080/github-webhook/ bir yere not edin ve tikini kaldırın.http://your-jenkins-domain.com/ghprbhook/ yazın. Yukarıda not ettiğimiz URL ile arasındaki farklılığa dikkat edin!!!x-www-form-urlencoded'i seçin.Issue comment, Pull request ve Push seçeneklerini seçin.Eğer sayfayı yenilediğinizde webhook URL'nin yanında yeşil bir tik varsa, iletişimde problem yok demektir. Link'e tıkladıktan sonra açılan sayfanın en altına indiğinizde, "Recent Deliveries" bölümünde tüm iletişim detaylarını görebilirsiniz.
Jenkins (GitHub plugin) servisini seçin.http://your-jenkins-domain.com/github-webhook/ yazın. Yukarıda not ettiğimiz URL ile arasındaki farklılığa dikkat edin!!!http://localhost:8080 adresine gidin.http://localhost:8080 adresine gidin.http://localhost:8080 adresine gidin.20 yazın.https://github.com/Inanzzz/nation yazın.sha1 yazın.https://github.com/Inanzzz/nation.git yazın.origin, "Refspec" alanına ise +refs/pull/*:refs/remotes/origin/pr/* yazın.${sha1} yazın.http://localhost:8080 adresine gidin.20 yazın.https://github.com/Inanzzz/nation.git yazın.origin/develop yazın. Hotfix ve release durumlarında testlerin çalıştırılmasını sağlar.origin/master yazın. Hotfix ve release durumlarında testlerin çalıştırılmasını sağlar.http://localhost:8080 adresine gidin.Jenkins log aşağıdaki gibi görünecek.
$ tail -f /var/log/jenkins/jenkins.log
Jan 14, 2017 8:02:59 PM org.jenkinsci.plugins.ghprb.GhprbTrigger stop
INFO: Stopping the ghprb trigger for project Nation-PullRequest
Jan 14, 2017 8:02:59 PM org.jenkinsci.plugins.ghprb.GhprbTrigger start
INFO: Starting the ghprb trigger for the Nation-PullRequest job; newInstance is true
Jan 14, 2017 8:03:06 PM hudson.model.Run execute
INFO: Nation-PullRequest #1 main build action completed: SUCCESS
Aşağıda görüldüğü gibi eğer build #1'in "Console Output" seçeneğini seçerseniz, build hakkında çok önemli bilgilere ulaşabilirsiniz.

Bu testi yapabilmek için, "Build History" listesinden en azından bir tane build olması gerekli.
http://localhost:8080 adresine gidin.Jenkins log aşağıdaki gibi görünecek.
$ tail -f /var/log/jenkins/jenkins.log
Jan 14, 2017 8:02:59 PM org.jenkinsci.plugins.ghprb.GhprbTrigger stop
INFO: Stopping the ghprb trigger for project Nation-Merge
Jan 14, 2017 8:02:59 PM org.jenkinsci.plugins.ghprb.GhprbTrigger start
INFO: Starting the ghprb trigger for the Nation-Merge job; newInstance is true
Jan 14, 2017 8:03:06 PM hudson.model.Run execute
INFO: Nation-Merge #1 main build action completed: SUCCESS
Aşağıda görüldüğü gibi eğer build #1'in "Console Output" seçeneğini seçerseniz, build hakkında çok önemli bilgilere ulaşabilirsiniz.

Yerel ortamda feature/update-gitignore isminde yeni bir tane branch yaratıp, remote GitHub kütüphanemize iletiyoruz. Jenkins build işlemini, biz pull request'i yarattıktan sonra çalıştırır, önce değil. Kısacası bizi bekler!
Yerel feature/update-gitignore branch'ı remote GitHub kütüphanemize ilettiğimizde, Jenkins log aşağıdaki gibi görünecek.
$ tail -f /var/log/jenkins/jenkins.log
Jan 14, 2017 8:20:38 PM org.jenkinsci.plugins.ghprb.GhprbRootAction handleAction
WARNING: Request not known for event: push
Jan 14, 2017 8:20:38 PM org.jenkinsci.plugins.github.webhook.subscriber.DefaultPushGHEventSubscriber onEvent
INFO: Received PushEvent for https://github.com/Inanzzz/nation
Jenkins feature/update-gitignore branch'ı için yaratılan testi başlatıp bitirdikten sonra, Jenkins log aşağıdaki gibi görünecek.
$ tail -f /var/log/jenkins/jenkins.log
Jan 14, 2017 8:21:35 PM org.jenkinsci.plugins.ghprb.GhprbRootAction handleAction
INFO: Checking PR #3 for Inanzzz/nation
Jan 14, 2017 8:21:35 PM org.jenkinsci.plugins.ghprb.GhprbTrigger handlePR
INFO: Checking PR #3 for job Nation
Jan 14, 2017 8:21:35 PM org.jenkinsci.plugins.ghprb.GhprbPullRequest
INFO: Created Pull Request #3 on Inanzzz/nation by Inanzzz () updated at: 1/14/17 8:35 PM SHA: 8f81f2b57df92b7ba0886e9f4ba3c8431b352581
Jan 14, 2017 8:21:35 PM org.jenkinsci.plugins.ghprb.GhprbPullRequest updatePR
INFO: Pull request #3 was updated on repo Inanzzz/nation but there aren't any new comments nor commits; that may mean that commit status was updated.
Jan 14, 2017 8:21:51 PM hudson.model.Run execute
INFO: Nation #3 main build action completed: SUCCESS


Eğer Jenkins GUI'ye giderseniz, build hakkında daha fazla bilgi görebilirsiniz.

Eğer pull request'e test this please yorumunu yazarsanız, Jenkins son çalıştırılan testi tekrar çalıştırır. Jenkins'in genel ayarlarındaki "GitHub Pull Request Builder" bölümünde veya burada diğer özel "yorum komutlarını" görebilirsiniz.
$ tail -f /var/log/jenkins/jenkins.log
Jan 14, 2017 8:42:16 PM org.jenkinsci.plugins.ghprb.GhprbRootAction handleAction
INFO: Checking issue comment 'test this please' for repo Inanzzz/nation
Jan 14, 2017 8:42:16 PM org.jenkinsci.plugins.ghprb.GhprbTrigger handleComment
INFO: Checking comment on PR #3 for job Nation
Jan 14, 2017 8:42:17 PM org.jenkinsci.plugins.ghprb.GhprbPullRequest updatePR
INFO: Pull request #3 was updated/initialized on Inanzzz/nation at 1/14/17 8:55 PM by Inanzzz (comment)
Jan 14, 2017 8:42:27 PM hudson.model.Run execute
INFO: Nation #4 main build action completed: SUCCESS

Burada elimizde mevcut olan feature/update-gitignore branch'ını kullanacağız yani hemen "Merge pull request" butonuna basabilirsiniz.
"Merge pull request" butonuna bastıktan sonra, Jenkins log aşağıdaki gibi görünecek.
$ tail -f /var/log/jenkins/jenkins.log
INFO: Received PushEvent for https://github.com/Inanzzz/nation
Jan 14, 2017 2:24:22 PM org.jenkinsci.plugins.github.webhook.subscriber.DefaultPushGHEventSubscriber$1 run
INFO: Poked Nation-Merge
"Confirm merge" butonuna bastıktan sonra, Jenkins log aşağıdaki gibi görünecek.
$ tail -f /var/log/jenkins/jenkins.log
Jan 14, 2017 2:24:24 PM com.cloudbees.jenkins.GitHubPushTrigger$1 run
INFO: SCM changes detected in Nation-Merge. Triggering #9
Jan 14, 2017 2:24:35 PM hudson.model.Run execute
INFO: Nation-Merge#9 main build action completed: SUCCESS



Eğer Jenkins GUI'ye giderseniz, build hakkında daha fazla bilgi görebilirsiniz.
