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ı
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-419.png?resize=560%2C317&ssl=1)
-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.
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-420.png?resize=570%2C349&ssl=1)
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-421.png?resize=556%2C180&ssl=1)
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."'
}
}
}
}
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-422.png?resize=689%2C491&ssl=1)
-Github’a jenkins file pushluyoruz.git add.
git commit -m "First Commit Omer"
git push origin main
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-423.png?resize=436%2C293&ssl=1)
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-424.png?resize=389%2C177&ssl=1)
4-Git repo üzerinden jenkins job oluşturulması
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-425.png?resize=432%2C334&ssl=1)
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-426.png?resize=372%2C248&ssl=1)
-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.
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-428.png?resize=633%2C685&ssl=1)
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-427.png?resize=678%2C713&ssl=1)
-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ı.
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-429.png?resize=800%2C544&ssl=1)
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-430.png?resize=675%2C402&ssl=1)
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.
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-432.png?resize=650%2C567&ssl=1)
-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.
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-433.png?resize=358%2C180&ssl=1)
-Oluşturduğumuz build pipeline’da setting kısmından aşağıdaki seçeneği seçiyoruz.
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-434.png?resize=543%2C246&ssl=1)
-Test için local git repo’da bir dosya oluşturup bunu github’a pushluyoruz.
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-435.png?resize=560%2C338&ssl=1)
-Ve build pipeline otomatik olarak çalıştı.
![](https://i0.wp.com/onuromertunc.com/wp-content/uploads/image-436.png?resize=755%2C584&ssl=1)