PHP unit test using Jenkins and Ansible script


1.1 Create the Jenkins Job

Jenkins -> New Item -> Freestype project – >

Enter the project name


1.2 At the Build section,  “Add build step” ->  Execute shell , enter the ansible-playbook details to be executed

1.3 In the “Post-build Actions” ->  “Add post-build actions” -> “Publish JUnit test result report” -> and set “Test reports XMLs” to the php unit test output xml file

2. Ansible playbook

– hosts: host1
base_dir: /projectdir/
– name: run testrunner
shell: php vendor/bin/phpunit –log-junit results/phpunit/phpunit.xml
chdir: “{{ base_dir }}/api”
register: phpunit_output
ignore_errors: yes

– name: rsync results/phpunit/phpunit.xml file to jenkins
command: rsync -vr root@host1:/project/results /var/lib/jenkins/jobs/Php-test/workspace/
delegate_to: localhost


eg: host1 , host where the php project is located

Install prometheus on centos7/rhel7

  1. Download prometheus monitoring tool. Latest downloads can be found at

    curl -LO “”

  2.  Untar the  file and move it to installation folder

    tar -xzvf prometheus-1.7.1.linux-amd64.tar.gz

  3. Move it to installation folder , here I am moving it to /var/lib

    mv prometheus-1.7.1.linux-amd64 /var/lib/prometheus

  4.  Edit the prometheus.yml file and update the scrape config– job_name: ‘server_monitoring’   scrape_interval: 15s   metrics_path: “/metrics”   static_configs:

        – targets:

            – server1:9100

            – server2:9100

            – server3:9100


            service: servers_usage


       – source_labels: [__address__]

         regex: ‘(.*)\:9108’

         target_label:  ‘instance’

         replacement:   ‘$1’

  5.  Add the start script in /etc/systemd/system/prometheus.service
    # echo “[Unit]
    Description=Prometheus Server
    ExecStart=/var/lib/prometheus/prometheus -config.file=/var/lib/prometheus/prometheus.yml -storage.local.path=/var/lib/prometheus/data[Install]”
  6. Start the prometheus service

    systemctl start prometheus

  7. Prometheus can now be accessible from http://<ip-address:9090


Install Grafana on CentOS/Rhel 7

  1. Download the rpm file


  2.  install initscripts & fontconfig

     yum install initscripts fontconfig urw-fonts

  3.   Install Grafana rpm file

    rpm -ivh grafana-4.6.3-1.x86_64.rpm

  4.  Enable and start Grafana service

    systemctl enable grafana-server.service

    systemctl start grafana-server.service

  5.  After that Grafana can be accessed using the url http://<ipaddress>:3000/. Default username and password is admin / admin.