TL;DR
In this post I will give step by step instructions for setting up Jenkins on AMI Linux host. Jenkins will run selenium webdriver tests on Firefox in headless mode.
Install Jenkins
1. `sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo`
2. `sudo rpm –import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key`
3. `sudo yum install jenkins`
4. `sudo yum remove java`
5. check that `java -version` is something like OpenJDK 64-Bit Server VM
6. check that jenkins runs on 8081
`sudo cat /etc/sysconfig/jenkins | grep JENKINS_PORT`
JENKINS_PORT=”8081″
7. `sudo service jenkins start`
8. `curl http://localhost:8081` should return jenkins home html page
Control Jenkins
`sudo service jenkins start/stop/restart`
log file `/var/log/jenkins/jenkins.log`
config file `/etc/sysconfig/jenkins`
Rvm
- `sudo yum install git`
- `sudo -u jenkins /bin/bash –login`
- `curl -sSL https://get.rvm.io | bash`
- `rvm install ruby_from_dot_ruby-version_file`
Firefox
Install it as jenkins user:
`sudo -u jenkins bash`
xvfb
`sudo yum install xorg-x11-server-Xvfb`
Check xvfb
first terminal:
`Xvfb :1 -screen 0 1280x768x24`
another terminal:
`export DISPLAY=:1`
`firefox`
**Note**
It is known that after sudo yum update, xvfb will fail with following error.
`Xvfb: symbol lookup error: Xvfb: undefined symbol: pixman_glyph_cache_create`
And console with firefox will report:
`Xvfb: symbol lookup error: Xvfb: undefined symbol: pixman_glyph_cache_create`
In order to resolve this issue, you need to run:
`rm /usr/local/lib/libpixman-1.so.0`
Jenkins security
Follow instructions from paragraph Password protect Jenkins.
## Jenkins plugins
Paragraph Install Jenkins plugins.
Install rvm plugin.
Configure Jenkins to run cucumber tests
0. become jenkins user: `sudo -u jenkins /bin/bash –login`
in `/var/lib/jenkins` folder, create ssh key.
copy `/var/lib/jenkins/.ssh/id_rsa.pub` to github deploy keys.
1. login to jenkins web console (before create your account)
2. create new job
3. project name: unique_project_name_by_your_decision
4. check discard old builds, strategy log rotation, max # of builds to keep 10.
5. source code management is git, your repository url is your git repository *.git
6. credentials: none
7. branches to build: */master (or whatever you like)
8. Build environment, check run the build in a RVM-managed environment
9. Implementation: e.g. ruby-2.1.2@gemsetname
10. ssh agent check
11. select credentials jenkins
12. add credential jenkins if not present
13. scope: global, type: ssh private key, username: jenkins, private key from a file on jenkins master: /var/lib/jenkins/.ssh/id_rsa
14. add build step: execute shell, `cd $WORKSPACE`
15. add build step: execute shell, `bundle install`
16. add build step: execute shell, `cucumber features -f html – o reports/report_$BUILD_TAG.html`
17. save
18. `ssh to AMI linux instance
19. `sudo -u jenkins /bin/bash –login`
20. Only first time create your test configuration files that are not present in git repository. E.g. application.yml file (repository README.md has content instructions ) in
`vi /var/lib/jenkins/jobs/unique_project_name_by_your_decision/workspace/config/application.yml`
21. You can check cucumber execution report in workspace/reports
**Tip and tricks**
Once you have one jenkins job, in order to create another one, just use feature `copy existing item` in New Item feature. Edit configuration as appropriate and hit OK. Run the job that will fail. After that, do action from step 21. and task is ready.
Jenkins rest api
1. first obtain csrf crumb
`curl http://jenkins_username:jenkins_password@10.30.105.232:8081/crumbIssuer/api/json`
you will get:
`{“crumb”:”f4828a00ccfe682b59b3977f8fdc8134″,”crumbRequestField”:”.crumb”}`
2. start jenkins job:
`curl http://jenkins_username:jenkins_password@10.30.105.232:8081/job/job_name/build?token=jenkins_username_api_token -H “.crumb:f4828a00ccfe682b59b3977f8fdc8134” –data “”`
jenkins_username, password and api token are you jenkins credentials.
Runing firefox in headless mode
`sudo Xvfb :10 -ac` – start Xvfb server.
`export DISPLAY=:10`
This should be part of Jenkins job configuration.
Ant that it is, your AMI linux is ready to run your cucumber selenium webdriver tests in headless mode.