Continuous Integration (CI) has become an essential part of development environments. PHP Developers can make use of PHPCI and/or Jenkins for their CI.
PHPCI is a great tool by Block8, https://www.phptesting.org/. PHPCI provides a very intuitive interface for developers to understand where the solution broke. Especially for code analysis PHPCI is able to link to the Git repository and highlight the code that violated the syntax rule. However when it comes to complex solutions one might find that PHPCI might not provide the required feature.
Jenkins on the other hand has been around for longer and has a large repository of plugins that can become handy. So why not use PHPCI for code analysis and then trigger Jenkins to perform the remaining automation.
The extension at, https://github.com/kdemanuele/PHPCI-Jenkins-Plugin, is a simple Jenkins integration plugin for PHPCI. When the plugin is installed one can set PHPCI to trigger a Jenkins build.
Setting up the plugin
To setup the plugin upload the Jenkins.php to the PHPCI plugins folder. Note that this requires access to the server.
Once the plugin is installed, create a Jenkins token for the project and assign the token to the project in PHPCI.
Creating a Jenkins Token for the project
- Go to the Jenkins Project Page
- Navigate to the Project Configuration
- Scroll to the section ‘Build Triggers’
- Tick the checkbox for ‘Trigger builds remotely (e.g., from scripts)’
- In the input box that is shown, put in a Token to refer to the project
Setting up PHPCI configuration to trigger Jenkins build
- Go to ‘Edit Project’ for the desired project
- In the config section ‘PHPCI build config for this project’
- Add a YAML tag for complete. To ensure that the plugin is executed after the tests
- Under the complete tag place the ‘jenkins’ tag
- For the ‘jenkins’ tag set the following properties:
- url – which refers to the Jenkins URL (not the project URL)
- project – the name of the project that needs to be triggered after PHPCI tests
- token – the token that was created above.
Save the Jenkins and PHPCI changes and trigger a PHPCI Build. After all tests are executed you should see the ‘jenkins’ plugin executed.
Important Note: The plugin will not fail the build if it does not manage to communicate with Jenkins. Also Jenkins doesn’t provide useful information to determine that the build was successfully triggered so you must perform a manual check when setting up the configuration.
- PHPCI Official Website – https://www.phptesting.org/
- Jenkins Official Website – https://jenkins-ci.org/
- Trigger Jenkins build remotely – https://gist.github.com/IanVaughan/34a966a56e511f6ce64f