16/02/2019 - GIT, JENKINS, LINUX
In this example we are going to use SSH to integrate Jenkins with GitHub. As an example we will create a Pipeline project and run a dummy Jenkinsfile that is stored in the GitHub repository.
First of all you need to make sure that your Jenkins server can talk to GitHub over SSH. Follow steps defined in Connecting to GitHub with SSH page.
This is our dummy GitHub project and it is located at https://github.com/inanzzz/game
.
.
├── ci
│ └── pipeline
│ └── branch
│ ├── develop
│ │ └── Jenkinsfile
│ ├── feature
│ │ └── Jenkinsfile
│ └── master
│ └── Jenkinsfile
├── composer.json
├── composer.lock
├── src
│ └── Football.php
├── tests
│ └── FootballTest.php
└── vendor
Login to Jenkins UI and do the following.
GitHub-inanzzz
) for "Username" option.~/.ssh/id_rsa.pub
file into the textarea.In Jenkins's main page, click "New Item" link to create a new item called "Test" and then select "Pipeline" option in the following page.
https://github.com/inanzzz/game
for "Repository URL".GitHub-inanzzz
from "Credentials".*/master
to */develop
.ci/pipeline/branch/develop/Jenkinsfile
to "Scripth path".If you click "Build Now" link, it should successfuly run the first build and the console output should look like below.
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