CI Build Pipeline Triggers | Jenkins
Steps:
1-Git repository oluşturulması
2-Ssh auth
3-Git repo’da jenkins file oluşturulması ve commit
4-Git repo üzerinden jenkins job oluşturulması
5-Test triggers
1-Git repository oluşturulması

-Private Repository oluşturduktan sonra ssh ile bağlanacağımız bir için ssh key üretiyoruz ve çıkan keyi kaydediyoruz.
ls ~/.ssh
$ cat ~/.ssh/id_rsa.pub
-2-Github account setting’de aşağıdaki alana ssh key ekliyoruz.


3-Git repo’da jenkins file oluşturulması ve commit
Bir Jenkinsfile oluşturuyoruz ve aşağıdaki basic komutları yazarak oluşturduğumuz local git repoya kaydediyoruz.
pipeline {
agent any
stages {
stage('Build') {
steps{
sh 'echo "Build completed."'
}
}
}
}

-Github’a jenkins file pushluyoruz.git add.
git commit -m "First Commit Omer"
git push origin main


4-Git repo üzerinden jenkins job oluşturulması


-Aşağıdaki ayarları giriyoruz.
*Github ssh auth yaparken public key kullanmıştık. fakat jenkinsde private key kullanacağız.
*Add Credential > Jenkins tıkladıktan sonra aşağıdaki gibi dolduruyoruz.


-Save dedikten sonra artık jenkins bizim oluşturduğumuz pipeline’ı github üzerinden çekecek. Private repo olduğu için oluşturduğumuz Jenkinsfile daha güvenli.
-Test için pipeline > build now diyoruz ve başarılı bir şekilde çalıştı.


5-Test triggers
-Öncelikle oluşturduğumuz reposityor > setting > add webhook tıklıyoruz. Ve jenkins url yapıştırıyoruz. Content type json seçiyoruz ve git repoya herhangi bir push olduğunda trigger çalışacak şekilde ayarlıyoruz.

-Add webhook dedikten sonra github’un jenkins sunucusuna 8080 portu üzerinden ilgili konfigürasyonu gönderdiğinden emin olmalısınız. Aşağıdaki gibi yeşil tik işareti gelmeli.

-Oluşturduğumuz build pipeline’da setting kısmından aşağıdaki seçeneği seçiyoruz.

-Test için local git repo’da bir dosya oluşturup bunu github’a pushluyoruz.

-Ve build pipeline otomatik olarak çalıştı.
