Published August 18, 2018 by

Add Jenkins Slave node in Linux system

Jenkins uses a Master-Slave architecture to manage distributed builds. In this architecture, Master and Slave communicate through TCP/IP protocol.



In this tutorial, we learn how to add Jenkins slave node in Linux machine.


Step 1: Enable agent on TCP port


Go to Manage Jenkins > Configure Global Security




Scroll down and find Agents Section and click on Fixed port or random port.


Step 2: Add node


Go to Manage Jenkins > Manage Nodes



Click on New Node and give Node name.



Configure the Node parameter according to your requirements and Save. (Choose Launch method 'Launch slave agent via SSH') and other details like below screenshot.


Step 3: Activate Node

Now you can see Slave node is added successfully. But it is offline. To activate the slave node Click on Launch agent.


Go to Jenkins Master and Check, Now Jenkins Successfully connected with the slave node.


Now you can create a distributed job and build on the slave node.
Read More
Published August 17, 2018 by

Add Jenkins Slave node in Windows system

Jenkins uses a Master-Slave architecture to manage distributed builds. In this architecture, Master and Slave communicate through TCP/IP protocol.



In this tutorial, we learn how to add Jenkins slave node in windows machine.

Step 1: Enable agent on TCP port

Go to Manage Jenkins > Configure Global Security


Scroll down and find Agents Section and click on Fixed port or random port.

Step 2: Add node

Go to Manage Jenkins > Manage Nodes


Click on New Node and give Node name.



Configure the Node parameter according to your requirements and Save. (choose Launch method 'Launch agent via Java Web Start') and other details like below screenshot.



Now you can see Slave node is added successfully. But it is offline. To activate the slave node download Launch file.



Step 3: Activate Node

For activate slave node login into slave node's machine and copy Launch file here and Run it.

After, Successfully connected it shows one small pop-up for connection. Click on File > Install as a service



Go to Jenkins Master and Check, Now Jenkins Successfully connected with the slave node.


Now you can create a distributed job and build on the slave node.
Read More
Published August 17, 2018 by

How to Enable Password Authentication in AWS ec2 Instances

Please Note this article is only for information and practice. Please don't do this until you have any specific and valid reason. Because it's a big security hole by opening direct root access and enable password authentication of the server in the cloud.


By default, AWS ec2 instances don’t have password authentication. You have to use the private key to connect to the instances. However, you might have situations to use password-based authentication for your AWS ec2 instances.

In this tutorial, we have done the configuration to enable password authentication in AWS instance.

Step 1:

Login to AWS instances
ssh -i your-key.pem username@ip_address

Step 2:

Setup a password for the user using passwd command along with the username.
sudo passwd ubuntu

Step 3:


Edit sshd_config file.
sudo vim /etc/ssh/sshd_config

Find the Line containing 'PasswordAuthentication' parameter and change its value from 'no' to 'yes'

PasswordAuthentication yes

If you want to set up 'root' login, find  'PermitRootLogin' parameter and change its value from 'prohibit-password' to 'yes'
PermitRootLogin yes

After this changes save file and exit.

Step 4:

Restart the SSH service.

service ssh restart                                  ## for ubuntu

service sshd restart                                ## for centos

Step 5:

Now we can log in using the password you set for the user. For example,
ssh ubuntu@54.224.72.66
Read More
Published August 11, 2018 by

Create a First Job in Jenkins

In this post, we will learn how to create a job in the Jenkins. in this tutorial, we create a simple basic job. 

Create Job

login to Jenkins with your credentials. From the left pane, select a New Item, and click on create new jobs.


In the next window, type the name of the job such as First_Job and select job type as Freestyle Project and then click OK.


Add Build Step

In the next window, we will leave default options unchanged. Move to Build tab and select Add build step as an Execute shell. (If you have installed Jenkins on a window machine, select 'Execute Windows batch command' from the list)

Typing in command whatever you want.

Click the Save button and we complete the first job.

Start the Build

From the job dashboard, click Build Now and you will see job run.


Console Output

Now job run completely, click to build number and select Console Output. You will see the message 'This is my First Jenkins Job' show up inside the build log. That it you just complete the Jenkins job.



In the output, we can see various useful details such as who started the build, what is the workspace for the build, what was the command executed by Jenkins for the build along with the project name and output related to our commands. In the last, we would also see the overall status of job as successfully completed or not.
Read More
Published August 04, 2018 by

Send build artifacts over SSH in Jenkins

In this tutorial, we learn how to send build artifacts over SSH in a remote server in Jenkins.

Install the Plugin

Install 'Publish Over SSH Plugin' at Plug-in page.

Configure

1. Click Manage Jenkins in the sidebar then Configure System


2. Go to Publish over SSH section Click Add at SSH Servers


3. Enter any logical name to Name Enter IP Address or Hostname of the server to Hostname Enter the username to login to Username Enter any directory to Remote Directory where all the files are stored


4. Click Save at bottom of the page


Configuration in Job

In Jenkins Job Scroll down to the Build option and Add build step.

Select Send files or execute commands over SSH

Enter Source files path if you are writing*/ then Jenkins consider current job workspace 

Enter Exec command which you want to run on a remote server.


Click Save.

Run Job

Click Build Now



Read More
Published August 04, 2018 by

Upload Build to AWS S3 from Jenkins


If you are using Jenkins as your build server, you can easily and automatically upload your builds from Jenkins to AWS S3.

After doing a one-time configuration on your Jenkins server, syncing your builds to S3 is as easy as running a build.
There is no need to run anything in addition to running a build.

1. Create a new bucket for Jenkins in AWS S3



2. Install S3 Plugin in Jenkins

    Now go to Dashboard -> Manage Jenkins -> Manage Plugins and select        
    Available tab. Find "S3 plugin" and install it.



3. Go to Manage Jenkins and select Configure System. look for Amazon S3 Profiles


   
   Click on Add button for add S3 profile.

4. Please provide a profile name, access key and secret access key for your AWS account. also, Create an IAM user with the relevant S3 Permissions.


    Click on Save button.

5. Configure in Jenkins Job
    Go to Jenkins job and find Post Build Actions and add a new Post Build Action and select Publish Artifacts to S3 Bucket.



6. Configure your S3 Profile and define the files to upload.
  
     Click on Save button.

Now each time you run a (successful) build, your artifacts will automatically upload to your S3 bucket.

7. Click Build Now
8. Go to AWS S3 and verify it's upload or not.

       Here you can see all the files are uploaded in Jenkins Build number's folder.
Read More
Published August 01, 2018 by

Run Powershell scripts in Jenkins

Jenkins has been primarily used for automating jobs and tasks on Linux servers. In this tutorial, we will be configuring Jenkins to execute Powershell scripts on Windows.



Powershell Plugin

Jenkin’s Powershell plugin is a useful tool for running Powershell scripts on Windows machine via Jenkins.

Plugin installation

1. Login to Jenkins and navigate to Manage Jenkins > Manage Plugins.




2. Click on the Available tab and Enter PowerShell in the filter box.



3. Select the plugin showing by name PowerShell Plugin.

4. Click on Install without restart.

The PowerShell plugin is now installed. and we can use in a Jenkins job.


Use PowerShell

In Jenkins Job Scroll down to the Build option and Add build step.

Select Windows PowerShell, inside the text box where the below Powershell script is to be supplied:



Here you can write PowerShell script according to your requirements.


Read More
Published August 01, 2018 by

Build Jenkins Job with Condition and Parameter


If you look forward to Jenkins for most of your development operations then, at some point in time you might have felt the need of something which allows you to condition your steps. Of course, it is not such a good idea to create individual jobs each time you want to run and test specific build step/s. The solution is to use a Conditional BuildStep plugin.

This plugin gives you additional control over your build steps by simply allowing you to add various conditional checks. There are several conditions that you may choose from, and these are all defined.

Scenario:

Suppose we want to start or stop apache service via reading user parameter.

Install Conditional BuildStep plugin.



Configure Job

1. Go to Jenkins Job and tick This project is parameterized.



2. Click on Add Parameter and select Choice Parameter



3. Here give a name of the parameter and also define Choices of a parameter.
    Remember name is act as a Variable name



4. Scroll down to the Build option and Add build step.

    Select Conditional steps(multiple)





5. Select Run? is Strings Match
  
    Create two Conditional steps as per below

    Condition 1: (for apache START)



   Condition 2: (for apache STOP)



Also, you can create a simple Execute shell script



6. Click Save

7. Now build job with a parameter.


Select your choice and Build.



Read More