botbotbot 's blog

Jenkins CI

Jenkins-CI - Extendable CI Server

Install Jenkins::


# Don't use only apt-get install jenkins that old version
$ wget -q -O - | sudo apt-key add -
$ sudo vim /etc/apt/sources.list
# add the following entry
# deb binary/
$ sudo apt-get update
$ sudo apt-get install jenkins


brew update
brew install jenkins

Allow others to access jenkins

Original From Setting up an Apache Proxy for port 80 -> 8080 but it use old version of apache2

$ sudo apt-get install apache2
$ sudo a2enmod proxy
$ sudo a2enmod proxy_http
$ sudo a2dissite 000-default.conf

Create “jenfins.conf” in /etc/apache2/sites-available

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  ServerAlias ci
  ProxyRequests Off
  <Proxy *>
		Order deny,Alloww
		Allow from all
  ProxyPreserveHost on
  ProxyPass / http://Proxylocalhost:8080/
$ sudo a2ensite jenkins
$ sudo service apache2 restart

Jenkins Job Workspace::

  1. look jenkins home directory in Manage Jenkins > Configure System > Home directory
  2. In Home directory clicks Advanced... Buttons.
  3. look Workspace Root Directory. Normally it is workspace.
  4. your job workspace is < jenkins home directory > /jobs/< your jobs > / < workspace >

Jenkins backup and Import Configure::

Backup Job Configure

http://yourjenkinsserver/job/<project name>/config.xml

Import Job Configure

  1. look jenkins home directory in Manage Jenkins > Configure System > Home directory
  2. go to < jenkins home directory >/jobs
  3. go to < your jobs directory >
  4. replace your backup config.xml with config.xml
  5. reload jenkins with


Jenkins Trigger via git hook::

Setup Configure

  1. Install Git Plugin
  2. In Job Configure > Source Code Management > Select Git
  3. add your git repository url to Repository URL
  4. Select Poll SCM in Build Triggers and you can leave Schedule as blank
  5. Save Configure

Git Hook to trigger Jenkins

  1. If you use linux you have to install curl. That was installed osx.

    $ sudo apt-get install curl

  2. You can trigger jenkins with this url

    http://yourjenkinsserver/git/notifyCommit?url=<URL of the Git repository>

  3. You can trigger jenkins after git push by

    # git don't have post-push hook
    $ git push && curl http://yourjenkinsserver/git/notifyCommit?url=$(git remote -v | grep -m 1 -oh "git@.*git")
  4. You can use git alias to make short cmd by edit .git/config in your git repository

       trig-jenkins = !curl http://yourjenkinsservergit/notifyCommit?url=$(git remote -v | grep -m 1 -oh "git@.*git")
       push-wt = !git push && git trig-jenkins

call your alias by

   $ git trig-jenkins
   $ git push-wt

Jenkins with Python::


  1. Install ShiningPanda Plugin
  2. In Manage Jenkins > Configure System > Python clicks “Python installations” button.
  3. Config your python environments
  4. Save

Configure Job to run with python

  1. In Job Configure > Build > Add build step > {Python Builder, VirtualEnv Builder}
  2. Select your Python version
  3. Nature select shell
  4. In command add your run script

    # example
    export LANG=en_US.UTF-8
    python develop
    nosetests --with-coverage --cover-erase --cover-package=core,bin --cover-html --with-xunit
  5. (Optional) Publish Test Result Report

    5.1 Use nosetests to generate xml result in xunit format

    $ nosetests --with-xunit  # nosetests.xml is default name of xml

    5.2 Add post-build action > Publish JUnit test result report
    5.3 Add “nosetests.xml” in Test report XMLs

  6. (Optional) Publish HTML reports

    6.1 Use nosetests to run

    $ nosetests --with-coveage --cover-html

    6.2 Add post-build action > Publish HTML reports

  7. (Options) Publish your product

    7.1 Add post-build action > Archive the artifacts
    7.2 Add your file name

Start/Stop Jenkins that installed via Homebrew

# launchd start jenkins at login:
$ ln -sfv /usr/local/opt/jenkins/*.plist ~/Library/LaunchAgents
# start jenkins
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist
# stop jenkins:
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist

Jekins Reset Password

  1. Go to Jenkins Home Path
    (debian) /var/lib/jenkins
  2. Edit config.xml
  3. Set < userSecurity> tag to false
  4. Delete < authorizationStrategy> and < securityRealm> tags
  5. Restart Jenkins
$ sudo service jenkins restart

SSH Key on Jenkins

$ sudo su - jenkins
$ ssh-keygen -t rsa -C ""
$ cat ~/.ssh/

Jekins git pulling timeout after 10 min

  1. Edit job configuration, In git plugion section
  2. Click Add > Advanced clone behaviours > Set Timeout

Jenkins running parallel scripts

# wokr in any shell
$ &   # run in background (sub-shell)
$     # run in foreground (shell)

Jenkins with

  1. Move fast and don’t break things! Testing with Jenkins, Ansible and Docker
  2. jenkins-docker-sample
  3. Use Docker + Jenkins to run GitHub tests
# add jenkins to docker group
$ sudo gpasswd -a jenkins docker # or sudo adduser jenkins docker
$ sudo service restart
$ sudo service jenkins restart

Jenkins Plugins - Install via Terminal::

  1. Git Plugin
  2. ShiningPanda Plugin - Python support to Jenkkins
  3. Green Balls
  4. Build Pipeline Plugin
  5. Build Monitor Plugin
  6. Jenkins Sounds plugin
  7. Robot Framework Plugin
  8. Sonar plugin
  9. Violations - generates reports static code violation detectors
  10. Publish over SSH
  11. Jenkins Job DSL

Jenkins References::

  1. Installing Jenkins on Ubuntu
  2. Jenkins Debian packages
  3. Jenkins and Python
  4. Jenkins :: สรุป plugin ยอดฮิตประจำเดือนพฤษภาคม ปี 2557
  5. Jenkins Setup on Os X server
  6. Jenkins and Python
  7. Integration of pylint into jenkins
  8. Running Jenkins in Docker Containers