Bu örneğimizde SSH kullanarak Jenkins'i GitHub'a entegre edeceğiz. Örnek olarak GitHub kütüphanesinde bulunan bir Jenkinsfile dosyasını kullanarak, Jenkins içinde bir Pipeline projesi yaratacağız.


Ön şartlar


Öncelikle, Jenkins sunucunuzun GitHub ile SSH üzerinden konuşabildiğinden emin olmanız gerekir. Connecting to GitHub with SSH sayfasındaki adımları takip edebilirsiniz.


Uygulama


Bu bizim örnek GitHub projemiz ve https://github.com/inanzzz/game adresinden ulaşılabilir haldedir.


.
├── ci
│ └── pipeline
│ └── branch
│ ├── develop
│ │ └── Jenkinsfile
│ ├── feature
│ │ └── Jenkinsfile
│ └── master
│ └── Jenkinsfile
├── composer.json
├── composer.lock
├── src
│ └── Football.php
├── tests
│ └── FootballTest.php
└── vendor

Jenkins


Jenkins UI'ye giriş yaptıktan sonra aşağıdakileri uygulayın.


Kimlik bilgileri


  1. Sol taraftaki "Credentials" linkini tıklayın.

  2. Önce "Jenkins/Global", daha sonrada "Add credentials" linkini tıklayın.

  3. "Kind" bölümünden "SSH Username and private key" seçeneğini seçin.

  4. "Username" bölümüne bir isim belirleyin (örneğin: GitHub-inanzzz).

  5. "Enter directly" radio butonuna tıklayın ve daha sonra ~/.ssh/id_rsa.pub dosyasının içeriğini text alanına yapıştırın.

  6. Kaydedip çıkın.

Pipeline


Jenkins'in ana sayfasında "New Item" linkine tıklayıp "Test" isminde yeni bir item yaratın ve sonraki sayfadan "Pipeline" seçeneğini seçin.


  1. "Pipeline" bölümünden "Pipeline script from SCM" seçeneğini seçin.

  2. SCM olarak "Git" seçin.

  3. "Repository URL" için https://github.com/inanzzz/game linkini kullanın.

  4. "Credentials" bölümünden GitHub-inanzzz seçeneğini seçin.

  5. İsteğe bağlı olarak */master*/develop olarak değiştirin.

  6. "Scripth path" bölümüne ci/pipeline/branch/develop/Jenkinsfile yazın.

  7. Kaydedip çıkın.

"Build Now" linkine tıklarsanız, ilk build başarıyla çalıştırılmalı ve konsol çıktısı aşağıdakine benzemelidir.


Started by user admin
Obtained ci/pipeline/branch/develop/Jenkinsfile from git https://github.com/inanzzz/game
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/Game
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
using credential 7a41495c
Cloning the remote Git repository
Cloning repository https://github.com/inanzzz/game
> git init /var/lib/jenkins/workspace/Game # timeout=10
Fetching upstream changes from https://github.com/inanzzz/game
> git --version # timeout=10
using GIT_SSH to set credentials
> git fetch --tags --progress https://github.com/inanzzz/game +refs/heads/*:refs/remotes/origin/*
> git config remote.origin.url https://github.com/inanzzz/game # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url https://github.com/inanzzz/game # timeout=10
Fetching upstream changes from https://github.com/inanzzz/game
using GIT_SSH to set credentials
> git fetch --tags --progress https://github.com/inanzzz/game +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/develop^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/develop^{commit} # timeout=10
Checking out Revision f63bf36b (refs/remotes/origin/develop)
> git config core.sparsecheckout # timeout=10
> git checkout -f f63bf36b
Commit message: "Very first commit"
First time build. Skipping changelog.
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] timeout
Timeout set to expire in 1 min 0 sec
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Code Pull)
[Pipeline] echo
Pulling...
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] echo
Building...
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] echo
Testing...
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Image Build)
[Pipeline] echo
Building...
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Image Push)
[Pipeline] echo
Pushing...
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy)
[Pipeline] echo
Deploying...
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS