LoginSignup
4
2

More than 5 years have passed since last update.

Ansibleでcentos7 にJenkinsを設定する方法(PHPUnit、インスペクタライブラリの設定含む)

Last updated at Posted at 2016-10-03

Ansibleでcentos7 にJenkinsを設定する方法(PHPUnit、インスペクタライブラリの設定含む)

プロキシエラーにならないように対策済み
ライブラリは本番環境と開発環境でcomposerを切り分けなくて
いいようにする為composer経由ではない方法で設定しています。

動作確認用のテストソースもレポジトリに格納しています。

重要な部分の抜粋

jenkinsの設定部

roles/jenkins/tasks/main.yml
   - name: Get jenkins yum repository
     yum_repository:
       name: jenkins
       description: jenkins yum repo
       baseurl: http://pkg.jenkins-ci.org/redhat-stable/

   - name: Install jenkins-ci.org.key
     rpm_key:
       key: http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key

   - name: Install Jenkins
     yum: name=jenkins state=present

   - name: Start Jenkins service
     service: name=jenkins state=started

   - name: Jenkins auto boot
     command: chkconfig jenkins on

   - name: Configure jenkins.conf
     copy: >
      src=./templates/jenkins.conf
      dest=/etc/httpd/conf.d/jenkins.conf
        owner=root
        group=root
        mode=0644

   - name: Configure config.xml
     copy: >
      src=./templates/config.xml
      dest=/var/lib/jenkins/config.xml
        owner=jenkins
        group=jenkins
        mode=0644

   - name: Restart Jenkins service
     service: name=jenkins state=restarted

Jenkinsで作成したジョブから各種ライブラリを連動させるためのphing設定

ansible_jenkins/phing/build.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- phing実行時に引数がない場合はdefaultの"build"が実行される -->
<project name="jenkins_phing" default="build">

    <!-- 変数設定 -->
    <property name="targetDir" value="./tests/" override="false"/>
    <property name="outputDir" value="./reports/" override="false"/>
    <property name="phpmdRulesets" value="codesize,controversial,design,naming,unusedcode" override="false"/>

    <!-- 初期設定 -->
    <target name="prepare">
        <echo msg="初期設定"/>
        <delete dir="./reports"/>
        <mkdir dir="./reports"/>
    </target>

    <target name="phpunit" description="テスト結果の推移">
        <phpunit haltonfailure="false" printsummary="true" pharlocation="/usr/local/bin/phpunit">
            <batchtest>
                <!-- 対象ディレクトリをtests下に設定 -->
                <fileset dir="${targetDir}">
                    <!-- 対象ファイルの設定 -->
                    <include name="**/*TEST.php"/>
                </fileset>
            </batchtest>
            <!-- 結果をXMLでphpunit.xmlとして出力 -->
            <formatter type="xml" outfile="${outputDir}/phpunit.xml"/>
        </phpunit>
    </target>

    <target name="phpcs" description="Checkstyle警告の推移">
        <!-- 対象ディレクトリをtests下に設定 -->
        <exec executable="/usr/local/bin/phpcs">
            <arg path="tests"/>
            <arg value="--report=checkstyle"/>
            <!-- 結果をXMLでphpunit.xmlとして出力 -->
            <arg value="--report-file=${outputDir}/checkstyle-result.xml"/>
            <arg value="--standard=PSR2"/>
            <arg value="--extensions=php"/>
        </exec>
    </target>

    <target name="phpmd" description="PMD警告の推移">
        <exec executable="/usr/local/bin/phpmd">
            <!-- 対象ディレクトリをtests下に設定 -->
            <arg path="tests"/>
            <arg value="xml"/>
            <!-- ルールの設定 -->
            <arg value="codesize,controversial,design,naming,unusedcode"/>
            <arg value="--reportfile"/>
            <!-- 結果をXMLでpmd.xmlとして出力 -->
            <arg value="${outputDir}/pmd.xml"/>
        </exec>
    </target>

    <target name="phpcpd" description="重複コードの推移">
        <exec executable="/usr/local/bin/phpcpd">
            <!-- 対象ディレクトリをtests下に設定 -->
            <arg path="tests"/>
            <arg value="--log-pmd"/>
            <!-- 結果をXMLでcpd.xmlとして出力 -->
            <arg path="${outputDir}/cpd.xml"/>
        </exec>
    </target>

    <!-- 設定 build -->
    <target name="build" depends="prepare, phpunit, phpmd, phpcpd, phpcs"/>

</project>
4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2