Skip to content

Commit 4fa5955

Browse files
committed
updated
1 parent e066cd2 commit 4fa5955

13 files changed

+95
-4
lines changed

RoboFile.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<?php
2-
class Robofile
2+
class RoboFile extends \Robo\Tasks
33
{
4-
use Robo\Output;
5-
use Robo\Task\FileSystem;
6-
use Robo\Task\Git;
74

85
function post()
96
{
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
layout: post
3+
title: "Setting up Jenkins with Codeception"
4+
date: 2015-02-04 01:03:50
5+
---
6+
7+
![Jenkins](/images/jenkins/Jenk1.png)
8+
9+
A frequent question that appear from time to time is How to set up Codeception with [Jenkins](http://jenkins-ci.org/). Despite the growth of popularity of various Continuous Integration solutions Jenkins is still the most popular open-source solution on market. It is easy to setup and is easy to customize by applying various 3rd-party plugins. In this post we will take a look on how to setup testing process of **PHP project with Jenkins CI and Codeception**.
10+
11+
![Create new job in Jenkins](/images/jenkins/Jenk2.png)
12+
13+
## Preparing Jenkins
14+
15+
We will start from an empty Jenkins Server executed on localhost. Let's create a new Job for project tested with Codeception and name it PHPCodeceptionProject. Before we proceed to configuring it, lets install required plugins:
16+
17+
* **Git Plugin** - for building tests for Git repo
18+
* **Green Balls** - to display success results in green.
19+
* **xUnit Plugin**, **jUnit Plugin** - to process and display Codeception XML reports
20+
* **HTML Publisher Plugin** - to process Codeception HTML reports
21+
* **AnsiColor** - to show colorized console output.
22+
23+
![Jenkins Plugins](/images/jenkins/Jenk3.png)
24+
25+
## Basic Setup
26+
27+
Once everything is installed lets get back to configuring our newly created PHPCodeceptionProject. At first we will set up Git to checkout code and build. Depending on your needs you can set up periodical build or trigger build once the change is pushed to GitHub (you will need GitHub plugin for that). You may also set up **Jenkins as alternative to Travis CI** to build your pull requests with `GitHub pull request builder plugin`.
28+
29+
We will enable colors in console using Ansi Color
30+
31+
![Jenkins ANSI color](/images/jenkins/Jenk4.png)
32+
33+
Next and the most important part is to define build step. We won't create any sofisticated environment settings like setting up database and services. We assume that all we need to execute tests is to inctall composer dependencies and run codeception tests:
34+
35+
{% highlight bash %}
36+
composer install
37+
./vendor/bin/codecept run
38+
{% endhighlight %}
39+
40+
![Jenkins Codeception Build Step](/images/jenkins/Jenk5.png)
41+
42+
And that's the absolute minimum we need to execute tests in Jenkins. We can save project and execute the job. Jenkins will clone repository from Git, install composer dependencies and run Codeception tests. If tests fail you can review the console output to discover what went wrong.
43+
44+
![Jenkins Console Output](/images/jenkins/Jenk6.png)
45+
46+
## XML Reports
47+
48+
But we don't want to analyze console output for each failing build. Especially If Jenkins can collect and display the results inside its web UI. Codeception can export its results using JUnit XML format. To generate XML report on each build we will need to append `--xml` option to Codeception execution command. Codeception will print `result.xml` file containing information about test status with steps and stack traces for failing tests. Unfortunately Jenkins can't process such special like Codeception steps. So we will need to configure to print data only which strictly applies to xUnit xml format. This should be done in `codeception.yml`
49+
50+
{% highlight yaml %}
51+
settings:
52+
strict_xml: true
53+
{% endhighlight %}
54+
55+
Now let's update our build step to generate xml:
56+
57+
{% highlight bash %}
58+
composer install
59+
./vendor/bin/codecept run --xml
60+
{% endhighlight %}
61+
62+
and ask Jenkins to collect resulted XML. This can be done as part of Post-build actions. Let's add *Publish xUnit test result report* action and configure it to use with PHPUnit reports.
63+
64+
![Use PHPUnit xUnit builder for Jenkins](/images/jenkins/Jenk7.png)
65+
66+
Now we should specify path to PHPUnit style XML reports. In case of standard Codeception setup we should specify `tests/_output/*.xml` as a pattern for matching resulted XMLs. Now we save the project and rebuild it.
67+
68+
![Jenkins Result Trend](/images/jenkins/Jenk8.png)
69+
70+
Now for all builds we will see results trend graph that shows us percentage of passing and failing tests. We also will see a **Latest Test Result** link which will lead to to the page where all executed tests and their stats listed in a table.
71+
72+
73+
## HTML Reports
74+
75+
To get more details on steps executed you can ask Codeception to generate HTML report. Jenkins can display them as well.
76+
77+
{% highlight bash %}
78+
composer install
79+
./vendor/bin/codecept run --html
80+
{% endhighlight %}
81+
82+
Now we need HTML Publisher plugin configured to display generated HTML files. It should be added as post-build action similar way we did it for XML reports.
83+
84+
![Jenkins Codeception HTML Setup](/images/jenkins/Jenk9.png)
85+
86+
Jenkins should locate `report.html` located at `tests/_output/`. Now Jenkins will display HTML reports for each build.
87+
88+
![Jenkins HTML Report](/images/jenkins/Jenki10.png)
89+
![Jenkins Codeception HTML Results](/images/jenkins/Jenki11.png)
90+
91+
That's pretty much everything you need to get a simple Jenkins setup with Codeception.
92+
93+
94+

images/jenkins/Jenk1.png

20.1 KB
Loading

images/jenkins/Jenk2.png

40.3 KB
Loading

images/jenkins/Jenk3.png

69.7 KB
Loading

images/jenkins/Jenk4.png

6.09 KB
Loading

images/jenkins/Jenk5.png

9.88 KB
Loading

images/jenkins/Jenk6.png

89 KB
Loading

images/jenkins/Jenk7.png

40.5 KB
Loading

images/jenkins/Jenk8.png

18.8 KB
Loading

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy