For this installation, I used CentOS 7.2.1511 as Operating System with Java 1.8.0_91.
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key yum install jenkins
systemctl start jenkins.service
When you open Jenkins in browser (port 8080 default), you will notice that it requires a password. It also says where you can find it.
Start Jenkins on Boot time
systemctl enable jenkins.service
Install plugin Publish Over SSH
Open Jenkins and go to Manager Jenkins -> Manage plugins and search for Publish Over SSH plugin.
Publish Over SSH documentation: https://wiki.jenkins-ci.org/display/JENKINS/Publish+Over+SSH+Plugin
Generate SSH pair of keys for Jenkins user
- Ensure you are “jenkins” user in Linux infrastructure. Test it with:
- If you want to change your user and “sudo su jenkins” doesn’t work, try:
sudo su -s /bin/bash jenkins
Go to ssh directory in ~/.ssh/
ssh-keygen -t rsa
Type passphrase if you want, or just press Enter.
- Now your public key is idrsa.pub and your private key is idrsa file. Both files are in ~/.ssh/
Configure SSH in Jenkins
Go to Manage Jenkins – Configure system.
If the plugin is installed properly, you will see Publish over SSH area.
Set the private key
- In Key textbox, put your private key from jenkins user. (~/.ssh/id_rsa file)
Set the public key
- Place public key (idrsa.pub of Jenkins) in authorizedkeys file in remote server. (~/.ssh/authorized_keys – if it not exists, create it. chmod 600 it.)
SSH Server configuration
- Now configure SSH server and test configuration. Test Configuration should return Success.
Continuos Integration in Jenkins
- Start a freestyle project with a suggestive name.
- Select Git as source code. Clone with HTTPS or SSH.
- Specify branch you are using.
- Now create build steps. As you noticed, a new type of build step appeared, called “Send files or execute commands over SSH”. You can send files, execute commands, or both.
- If you want to transfer files from Git, use Source files textbox. When you want to copy a directory from Git, use directory/*, because directory/ transfer only directory’s files, not its subdirectories.
- Default exec timeout of a Publish over SSH build step is 120 seconds (120000 ms). Click on Advanced and modify or disable it, by setting it 0.