Difference between revisions of "Jenkins/Install and Plugins"
Line 54: | Line 54: | ||
If you have any plugins on Jenkins-master node that require external programs to run you should install these tools also on the slave. As all jobs are send to slaves these external programs should be there, most common are: | If you have any plugins on Jenkins-master node that require external programs to run you should install these tools also on the slave. As all jobs are send to slaves these external programs should be there, most common are: | ||
*git | *git | ||
*java | *java (this can be installed by Jenkins-master automatically) | ||
*ansible | *ansible | ||
*terraform | *terraform | ||
Create a workspace folder for jobs | |||
$ mkdir ~/jenkins-minion_workspace | |||
Add this slave in the master node console | |||
#Go to http://jenkins-master:8080 | |||
#Manage Jenkins > Manage Nodes > New Node with permanent agent and fill in with details | |||
[[File:Jenkins-master-add-new-slave.png|400px|none|left|Jenkins-master-add-new-slave]] | |||
Add credentials, then select them on the main new node screen and save configuration. | |||
[[File:Jenkins-minion-connection-credentials.png|300px|none|left|Jenkins-minion-connection-credentials]] | |||
= Configure and use ssh plugin = | = Configure and use ssh plugin = |
Revision as of 08:02, 2 May 2017
Install Jenkins
Pre-requisites: Java
Install Jenkins on Ubuntu from repository
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
Add repo to sources.list
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt-get update && sudo apt-get install jenkins
Verify
cat /etc/passwd | grep jenkins #check if user has been created without shell service jenkins status #check if service is running
First run
- Password preview
sudo vi /var/lib/jenkins/secrets/initialAdminPassword
- Url http://localhost:8080
- Select plugins you wish to install using web based wizard
- Once all downloaded, create your Admin user
- Once completed you will see: "Jenkins is ready! Your Jenkins setup is complete.", press Start Jenkins
Proxy if needed
If you run on restricted port system you cannot control the box firewall you may want to proxy your connection to Jenkins port :8080. You can install nGinx to do this for you
sudo apt-get install nginx sudo vi /etc/nginx/sites-enabled #then enable proxy_pass location / { proxy_pass http://127.0.0.1:8080; }
Configure ssh keys and permissions
Jenkins master node
$ sudo hostnamectl set-hostname jenkins-master $ sudo vi /etc/passwd #make sure jenkins user hava access to shell $ sudo passwd jenkins #set a password $ sudo su jenkins #become jenkins user $ cd ~ && ssh-keygen #generate ssh key pair $ ssh-copy-id jenkins@localhost #add public key to Jenkins (localhost) server, these might be minions workers $ sudo visudo #allow jenkins user to run sudo without password prompt and disble requireTTY; makes easier to run builds jenkins ALL=(ALL) NOPASSWD: ALL Defaults !requiretty
The !requiretty will allow Jenkins to run bash scripts in a background otherwise you receive an error:
sudo: no tty present and no askpass program specified
Build step 'Execute shell' marked build as failure
Jenkins slave (minion) worker
There is no need to install anything apart allowing the master node to ssh to it
$ sudo hostnamectl set-hostname jenkins-minion $ sudo adduser jenkins $ sudo passwd jenkins #set a password, may mach the master node one but not necessary $ sudo visudo #allow jenkins user to run sudo without password prompt; makes easier to run builds jenkins ALL=(ALL) NOPASSWD: ALL $ jenkins@master $ ssh-copy-id jenkins@minion #add ssh public key to slave node so master can send jobs to it
If you have any plugins on Jenkins-master node that require external programs to run you should install these tools also on the slave. As all jobs are send to slaves these external programs should be there, most common are:
- git
- java (this can be installed by Jenkins-master automatically)
- ansible
- terraform
Create a workspace folder for jobs
$ mkdir ~/jenkins-minion_workspace
Add this slave in the master node console
- Go to http://jenkins-master:8080
- Manage Jenkins > Manage Nodes > New Node with permanent agent and fill in with details
Add credentials, then select them on the main new node screen and save configuration.
Configure and use ssh plugin
This plugin allows to execute commands on remote hosts that you connect using ssh.
Install the plugin
- Install ssh plugin from Manage Jenkins > Manage Plugins > click on Available tab and search for ssh
- Configure remote hosts that Jenkins can connect goto Manage Jenkins > Configure System and fill in SSH remote hosts section with similar
Add remote ssh commands project
Once ssh remote hosts are added you can create a new project and in Build section you can choose Execute shell script on remote host using ssh. You can choose remote host from drop down list that contains hosts that you configured in the previous step.
Post build actions
There is whole bunch options you can do after your build has been successful. These can be picked up in your project > Configure > Post-build Actions section from drop down menu
- Build other projects
- Email notification
Schedule builds
Use Schedule Build Plugin for this.