Friday, 14 February 2014

Jenkins - Setup to schedule your repetitive scripts

What is Jenkins & when to use It?

When you have bunch of repeated jobs or scripts that you want to run, scheduled or sometimes manually triggered. Go for jenkins.

Its as easy as 

  •    Step 1: download
  •    Step 2: Install
  •    Step 3: Install Basic Plugins (optional)
  •    Step 4: Setup security
  •    Step 5: Create new job(s)
  •    Run

Jenkins is also used these days in the case of continuous integration, working with the Source Control, Review Boards, and other quality monitoring tools.

Step 1 : Download  :

Based on your environment, you can download the installer as shown below and install it.

Step 2 : Install   - Follow instructions.

  • Follow the installer instructions.
  • On Linux, firewall to be disabled if it blocks 8080 port
    service iptables off
  • After installation accessible at  http://<hostname>:8080  . Example http://localhost:8080
You will see the below screen after successful installation & start-up

Step 3 : Install  Plugins (Optional)

There are some default plugins. If you need more, pick and choose from the plugin list as shown below.

For Manual installation.
  • Download plugins from
  • copy the *.hpi/*.jpi file into the $JENKINS_HOME/plugins directory. 
  • Restart Jenkins (many containers let you do this without restarting the container)
I picked up few extra plugins Greenballs, XShell, setenv

Step 4 : Enable Security

1. Manage Jenkins -> Configure Global Security -> Enable Security.  

2. Configure as shown in the below picture.

  1. Enable Security
  2. Save  in jenkins database with Signup Enabled. This will enable you to add users later.
  3. Add privileges for admin user (which you will add through signup process)
  4. anonymous will have no privileges. Admin user - Select all checkboxes

  1. 5. Save, which will take you to the Login page as shown in the next image.

3. Signup for admin user from the Login Page. 

You are done with the basic security. You can go ahead and add other privileges using the admin user that is created.

Step 5 : Create new job

The dashboard now shows the job that was created.  and can now be run to see the progress

Some special settings when running on Linux Environment.

Jenkins in linux is created as a service and can be started using service jenkins start

The service will not be able access scripts or files within /root user  Say java -jar /root/test.jar will give you permission denied, even after setting the chmod appropriately. 

To solve this problem, the sudoers file has to be edited as mentioned below and execute the command prefixed with sudo. 

sudo java -jar /root/test.jar

Changes in the sudoers file
  • requiretty to be disabled for the jenkins service.  Add the Defaults:jenkins !requiretty  afterDefaults requiretty
    • visudo .(edit sudoers files)
    • Defaults requiretty
    • Defaults:jenkins !requiretty
  • add this line jenkins        ALL=(ALL)       NOPASSWD: ALL at the end

No comments:

Post a Comment