22/01/2017 - JENKINS, PHING
Aşağıdaki örneğimizde Jenkins, phing
komutu ile Nation
projemiz içinde build.xml
dosyası içinde belirlenmiş olan testleri çalıştıracak.
Sisteminizde Apache, git ve GitHub SSH kurulumunun yapıldığını varsayıyorum. Bunların haricinde aşağıdaki komutların çalıştırılması gerekir.
$ sudo apt-get install php5
$ sudo apt-get install libapache2-mod-php5
$ sudo apt-get install python-software-properties
$ sudo apt-get install php5-mysql
$ sudo apt-get install php5-mcrypt
$ sudo apt-get install php5-cli
$ sudo apt-get install php5-curl
$ sudo apt-get install php5-sqlite
$ sudo apt-get install sqlite3
$ sudo apt-get install libsqlite3-dev
$ sudo php5enmod mcrypt
# Restart apache server
$ sudo apt-get install curl
$ curl -sSk https://getcomposer.org/installer | php -- --disable-tls
$ sudo mv composer.phar /usr/local/bin/composer
$ CURL=`which curl`
$ sudo $CURL -O https://www.phing.info/get/phing-latest.phar
$ sudo mv ./phing-latest.phar /usr/local/bin/phing
$ sudo chmod 755 /usr/local/bin/phing
http://localhost:8080
adresine gidin.$ sudo service jenkins restart
ile yeniden başlatın..http://localhost:8080
adresine gidin.Build.xml dosyasının /workspace/Nation/
klasörünün içinde olduğunu varsayıyorum.
<?xml version="1.0" encoding="UTF-8"?>
<project name="nation" default="build" basedir=".">
<!-- FILESET -->
<fileset id="sourcecode" dir="${project.basedir}/src">
<include name="*.php" />
<include name="**/*.php" />
</fileset>
<!-- END -->
<!-- SUITE -->
<target name="build" depends="cache, composer, doctrine, fixtures, php-cs-fixer, behat" />
<!-- END -->
<!-- CACHE -->
<target name="cache">
<echo message="Clearing cache ..." />
<exec executable="rm" checkreturn="true" passthru="true">
<arg value="-rf" />
<arg value="${project.basedir}/var/cache/test/*" />
</exec>
</target>
<!-- END -->
<!-- COMPOSER -->
<target name="composer">
<echo message="Running composer self-update ..." />
<exec executable="composer" checkreturn="true" passthru="true">
<arg value="self-update" />
</exec>
<echo message="Running composer install ..." />
<exec executable="composer" checkreturn="true" passthru="true">
<arg value="install" />
<arg value="--no-interaction" />
</exec>
</target>
<!-- END -->
<!-- DOCTRINE -->
<target name="doctrine">
<echo message="Generating entities ..." />
<exec executable="bin/console" checkreturn="true" passthru="true">
<arg value="doctrine:generate:entities" />
<arg value="AppBundle" />
<arg value="--no-backup" />
<arg value="--env=test" />
</exec>
<echo message="Creating database ..." />
<exec executable="bin/console" checkreturn="true" passthru="true">
<arg value="doctrine:schema:create" />
<arg value="--no-interaction" />
<arg value="--env=test" />
</exec>
<echo message="Updating database ..." />
<exec executable="bin/console" checkreturn="true" passthru="true">
<arg value="doctrine:schema:update" />
<arg value="--force" />
<arg value="--no-interaction" />
<arg value="--no-debug" />
<arg value="--env=test" />
</exec>
</target>
<!-- END -->
<!-- FIXTURES -->
<target name="fixtures">
<echo message="Loading data fixtures ..." />
<exec executable="bin/console" checkreturn="true" passthru="true">
<arg value="doctrine:fixtures:load" />
<arg value="--no-interaction" />
<arg value="--no-debug" />
<arg value="--env=test" />
</exec>
</target>
<!-- END -->
<!-- PHP-CS-FIXER -->
<target name="php-cs-fixer">
<echo message="Checking coding standards ..." />
<exec executable="vendor/bin/php-cs-fixer" checkreturn="true" passthru="true">
<arg value="fix"/>
<arg value="--dry-run"/>
<arg value="--verbose"/>
<arg value="--diff"/>
</exec>
</target>
<!-- END -->
<!-- BEHAT -->
<target name="behat">
<echo message="Running behat tests ..." />
<exec executable="vendor/bin/behat" checkreturn="true" passthru="true">
<arg value="--suite=app"/>
<arg value="--format=progress"/>
</exec>
</target>
<!-- END -->
</project>
Bu örnek symfony kullanıyor o nedenle, aşağıdaki vhost dosyasının aktif olduğundan ve .php_cs
projenin ana klasöründe olduğundan emin olun.
<VirtualHost *:8082>
ServerName nation.dev
DocumentRoot "/var/lib/jenkins/workspace/Nation/web"
<Directory "/var/lib/jenkins/workspace/Nation/web">
Options Indexes FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/nation.dev.error.log
CustomLog ${APACHE_LOG_DIR}/nation.dev.access.log combined
</VirtualHost>
return PhpCsFixer\Config::create()
->setUsingCache(false)
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'ordered_imports' => true,
'array_syntax' => ['syntax' => 'short'],
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude(['app', 'bin', 'spec', 'var', 'vendor', 'web'])
->in(__DIR__)
)
;
Şu anda sisteme vagrant
olarak login olmuş durumdayız. Hemen jenkins
olarak login olup, build.xml dosyamızdaki testleri çalıştıralım.
$ vagrant@jenkins:~$
$ vagrant@jenkins:~$ sudo su -l jenkins
$ jenkins@jenkins:~$
$ jenkins@jenkins:~$ cd workspace/Nation/
jenkins@jenkins:~/workspace/Nation$ phing
Buildfile: /var/lib/jenkins/workspace/Nation/build.xml
nation > cache:
[echo] Clearing cache ...
[echo] Warming cache ...
// Warming up the cache for the test environment with debug true
[OK] Cache for the "test" environment (debug=true) was successfully warmed.
nation > composer:
[echo] Running composer install ...
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
// Clearing the cache for the dev environment with debug
// true
[OK] Cache for the "dev" environment (debug=true) was successfully cleared.
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets
Trying to install assets as relative symbolic links.
-- -------- ----------------
Bundle Method / Error
-- -------- ----------------
[OK] All assets were successfully installed.
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget
nation > doctrine:
[echo] Generating entities ...
Generating entities for bundle "AppBundle"
> generating AppBundle\Entity\Country
[echo] Updating database ...
Updating database schema...
Database schema updated successfully! "2" queries were executed
nation > fixtures:
[echo] Loading data fixtures ...
> purging database
> loading AppBundle\DataFixtures\ORM\LoadCountryData
nation > php-cs-fixer:
[echo] Checking coding standards ...
Loaded config default from "/var/lib/jenkins/workspace/Nation/.php_cs".
............
Legend: ?-unknown, I-invalid file syntax, file ignored, S-Skipped, .-no changes, F-fixed, E-error
Checked all files in 0.418 seconds, 8.500 MB memory used
nation > behat:
[echo] Running behat tests ...
....
2 scenarios (2 passed)
4 steps (4 passed)
0m0.24s (32.70Mb)
nation > build:
BUILD FINISHED
Total time: 7.1080 seconds
"Build History" alanında en azından bir tane build olduğunu varsayalım. Kendiniz build işlemini gerçekleştirin. Eğer çalıştırdığınız build'in "Console Output" bölümüne giderseniz, yukarıdakine benzer bir sonuç göreceksiniz.