First, we need to write a script which will be used by
Jenkins to build and test our software. In the following steps, we will tell
Jenkins to run this script every time there is a change in our source tree and to report us the results. In other words, when we commit or push changeset to our git repository,
Jenkins will invoke this script and when the script is done, It will notify us via email whether the build process was successful.
Jenkins viewpoint, we can invoke any command or build tool to build and test our software.
Jenkins will consider the build process as successful if the exit code of this command or build tool is
0. Any other exit code will be is a sign that the build has failed.
First, Clone our git repository to our development machine:
user@abc-01:~ # env GIT_SSH_COMMAND='ssh -i abc.key' git clone ssh://firstname.lastname@example.org/projects/abc.git Cloning into 'abc'... remote: Counting objects: 6, done. remote: Compressing objects: 100% (3/3), done. remote: Total 6 (delta 0), reused 0 (delta 0) Receiving objects: 100% (6/6), done. Checking connectivity... done. user@abc-01:~ # cd abc user@abc-01:~/abc #
Now, Create a new
build.sh. In this tutorial, this script will simply print that it was invoked and exit. In real life, this script will call our build tools (For example make, ant, rake ... ).
echo 'Hello from build script :-)' exit 0
Now, add, commit this file and push the changes:
user@abc-01:~/abc # git add build.sh user@abc-01:~/abc # git commit -m "adding build script" [master 67e9a97] adding build script 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 build.sh user@abc-01:~/abc # env GIT_SSH_COMMAND='ssh -i abc.key' git push ... To ssh://email@example.com/projects/abc.git 8be7ded..1935cca master -> master
Jenkins on your web browser. Go to
New Item. The following screen should appear:
Freestyle projectand click
Now , Go to
Source Code Management section and select
Repository URL- in this tutorial, The repository URL is
addbutton to the left of
Credentialsfield and select
Jenkinsand add your credentials. In this tutorial we use user with private key method.
After clicking ok, a new
abc key credential will appear in
credentials list. select it and wait - If
Jenkins can connect to the repository, you will not see any red error message.
Build section, click in
Add build step, select
Execute shell and enter the following script which call our
build.sh and return its exit code:
bash -ex build.sh exit $?
Save button in the bottom of the page to apply the changes. We are now ready to test our build.
Build now, You should see a new build in job list display.
Clicking the build, will show more details about it.