Triggering Remote Jenkins jobs from another Jenkins

Continuous integration and delivery is a very crucial part of software life cycle for automatic execution or deployment of the code. Usually we have single Jenkins for deployment, automation scripts etc. But many times different teams like Ops, Dev and QA create their own Jenkins for their own purposes.

Now if we talk about integrating everything at same place, it is not feasible to manage and re-create jobs. So solution is to make communication between two Jenkins servers and trigger build accordingly.

In this blog post, I will talk about how can you trigger a JOB-A (on remote-jenkins ) from JOB-B (on local-jenkins). The real scenario of this would be; when we are trying to trigger an automation script on Jenkins1 after successful completion of code deployment on Jenkins2.

For understanding this let assumes few things below-

  • We have a local job-  Job-B (local-jenkins) on server local-jenkins:8080
  • We have a remote job – Job-A (remote-jenkins) on server – remote-jenkins:8080

Now we want to trigger Job-A from Job-B. For achieving this we need to install few plugins in our local Jenkins (from which we want to trigger the job- local-jenkins in this case) –

Go to manage-Jenkins->configure system->Parameterized Remote Trigger Configuration, and do configuration as stated below-

remotetrigger1

You can add many remote servers. Now you have to do following changes in your local Jenkins job i.e. Job B.

buildsteps

buildinfo

Now save the configuration of your job and build your local job i.e. Job-B. Console of local job looks like below- local job

Console of Remote job looks like below – remotejob

You can see it says that started by local-Jenkins. So it has triggered this job on remote Jenkins from local Jenkins.

Similarly you can link multiple jobs to be build across different Jenkins server. I hope now you can easily integrate multiple Jenkins. Please add comments in case of any issues encountered. 🙂

 

Advertisements

Continuous integration with Jenkins in 5 minutes

When we talk about continuous integration; there are many tools like Jenkins, TeamCity, Bamboo etc. But Jenkins is the most popular because of its numerous plugin and free style configurations for jobs. Jenkins is an open source continues integration tool, which can be used for various purpose as it provides numbers of Plugin. There are two methods for installation and set up of Jenkins-

1) JAVA Web Archive (JAVA War file)

2) Native package

In this blog, I will discuss in details about how you can do Jenkins setup in 5 mins. So be with me and follow below steps-

Jenkins Installation & Set Up-

1) Download the Jenkins.war file from the following URL-http://jenkins-ci.org/

2) JDK 1.5 or above should be installed and a JAVA_HOME variable path should be set in advance

3) Open cmd/bash/shell according to operating system-Windows/Linux/Mac

4)  Locate the folder where Jenkins war file is downloaded

5) Type java -jar jenkins.war and hit Enter

6) Now open browser and hit the URL- localhost:8080

7) If a Jenkins page is opened in browser, that means you have done Jenkins setup

Above steps are for setting up Jenkins. Now Jenkins provide many plugins for various purposes, so you can do other configurations according to your need

Integrating GitHub to Jenkins-

Purpose of this integration is to perform all Github related task using Jenkins. For doing this configuration GitHub should be installed in the system on which Jenkins is deployed.

Please follow following steps for integrating Github-

1) In the Jenkins web GUI, click on Manage Jenkins link and then Click on Manage Plugin

jenkins

managejenkins

2) In the Manage Plugins, click on Available and install following plugins-

  1. a) Github API Plugin
  2. b) Git Client Plugin
  3. c) Git Plugin
  4. d) Github Plugin

 

3) After the installation of above Plugins, Click on Configure System under Manage Jenkins page and set the Git.exe property to its exact path as you can see in screenshot-

git

The Git path shown in the image may vary form system to system configuration.

Note- Above option will be available only if all Git Plugins stated above are correctly installed

4) Save all the configuration settings by clicking on Save button.

Creation of New Job and setting up a Git repository- I will be demonstrating a Github integration for a test project where all the test scripts are on github and Jenkins would be responsible for checking out the scripts and executing scripts on the machine where Jenkins is deployed. Please refer to following steps to do above set up

1) Click on New Job link in the Jenkins Dashboard.

2) Create a free style Software project and click on OK button.

newjob

3) After creating the job click on Configure and select Git under Source Code Management option-

job2.png

Enter a Repository URL as seen in the screenshot, which will be a combination of Username, Password and Repository Name.

Enter a Branch Name if you want to check out the code from a specific branch. If the field left blank, it will refer to Master branch by default.

4)Under Build option select your preferred build method for script execution and write the command accordingly- Please refer to attach screenshot-

build1

build2.png

5) Save the configuration and click on Build Now, if the set up is done correctly your scripts/code starts executing

This is about how you can do quick setup using Jenkins war file. similarly you can do setup using native programs of Jenkins and can create Client-Server modal for same.

Happy Learning 🙂