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
vars:
base_dir: /projectdir/
tasks:
– name: run testrunner
shell: php vendor/bin/phpunit –log-junit results/phpunit/phpunit.xml
args:
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

Leave a Reply

Your email address will not be published. Required fields are marked *