0

我正在尝试为我的 php 项目设置 Jenkins,但我遇到了权限问题。显然 Jenkins 无权读取/写入文件到build它创建的目录。我试过了,chmod -R 777 build但我仍然在 Jenkins 输出中得到了这个

PHP Warning:  file_put_contents(/var/www/build/logs/phploc.csv): failed to open stream: Permission denied in /var/www/vendor/phploc/phploc/src/Log/CSV/Single.php on line 68

这是我的 build.xml 文件。我可以在这里做些什么来允许詹金斯访问build它正在创建的目录吗?

<?xml version="1.0" encoding="UTF-8"?>

<project name="mylaravel" default="build" basedir=".">
 <target name="build"
   depends="prepare,lint,phploc,pdepend,phpmd-ci,phpcs-ci,phpcpd,phpdox,phpunit,phpcb"/>

 <target name="build-parallel"
   depends="prepare,lint,tools-parallel,phpunit,phpcb"/>

 <target name="tools-parallel" description="Run tools in parallel">
  <parallel threadCount="2">
   <sequential>
    <antcall target="pdepend"/>
    <antcall target="phpmd-ci"/>
   </sequential>
   <antcall target="phpcpd"/>
   <antcall target="phpcs-ci"/>
   <antcall target="phploc"/>
   <antcall target="phpdox"/>
  </parallel>
 </target>

 <target name="clean" description="Cleanup build artifacts">
  <delete dir="${project.basedir}/build/api"/>
  <delete dir="${project.basedir}/build/code-browser"/>
  <delete dir="${project.basedir}/build/coverage"/>
  <delete dir="${project.basedir}/build/logs"/>
  <delete dir="${project.basedir}/build/pdepend"/>
 </target>

 <target name="prepare" depends="clean" description="Prepare for build">
  <mkdir dir="${project.basedir}/build/api"/>
  <mkdir dir="${project.basedir}/build/code-browser"/>
  <mkdir dir="${project.basedir}/build/coverage"/>
  <mkdir dir="${project.basedir}/build/logs"/>
  <mkdir dir="${project.basedir}/build/pdepend"/>
  <mkdir dir="${project.basedir}/build/phpdox"/>
 </target>

 <target name="lint" description="Perform syntax check of sourcecode files">
  <apply executable="php" checkreturn="1">
   <arg value="-l" />

   <fileset dir="${project.basedir}/app">
    <include name="**/*.php" />
   </fileset>

   <fileset dir="${project.basedir}/app/controllers">
    <include name="**/*.php" />
   </fileset>

   <fileset dir="${project.basedir}/app/models">
    <include name="**/*.php" />
   </fileset>

   <fileset dir="${project.basedir}/app/tests">
    <include name="**/*.php" />
   </fileset>
  </apply>
 </target>

 <target name="phploc" description="Measure project size using PHPLOC">
  <exec executable="${project.basedir}/vendor/bin/phploc" logoutput="true">
   <arg value="--log-csv" />
   <arg value="${project.basedir}/build/logs/phploc.csv" />
   <arg path="${project.basedir}/app" />
  </exec>
 </target>

 <target name="pdepend" description="Calculate software metrics using PHP_Depend">
  <exec executable="${project.basedir}/vendor/bin/pdepend" logoutput="true">
   <arg value="--jdepend-xml=${project.basedir}/build/logs/jdepend.xml" />
   <arg value="--jdepend-chart=${project.basedir}/build/pdepend/dependencies.svg" />
   <arg value="--overview-pyramid=${project.basedir}/build/pdepend/overview-pyramid.svg" />
   <arg path="${project.basedir}/app" />
  </exec>
 </target>

 <target name="phpmd"
         description="Perform project mess detection using PHPMD and print human readable output. Intended for usage on the command line before committing.">
  <exec executable="${project.basedir}/vendor/bin/phpmd" logoutput="true">
   <arg path="${project.basedir}/app" />
   <arg value="text" />
   <arg value="${project.basedir}/phpmd.xml" />
  </exec>
 </target>

 <target name="phpmd-ci" description="Perform project mess detection using PHPMD creating a log file for the continuous integration server">
  <exec executable="${project.basedir}/vendor/bin/phpmd" logoutput="true">
   <arg path="${project.basedir}/app" />
   <arg value="xml" />
   <arg value="${project.basedir}/phpmd.xml" />
   <arg value="--reportfile" />
   <arg value="${project.basedir}/build/logs/pmd.xml" />
  </exec>
 </target>

 <target name="phpcs"
         description="Find coding standard violations using PHP_CodeSniffer and print human readable output. Intended for usage on the command line before committing.">
  <exec executable="${project.basedir}/vendor/bin/phpcs" logoutput="true">
   <arg value="--standard=${project.basedir}/phpcs.xml" />
   <arg path="${project.basedir}/app" />
  </exec>
 </target>

 <target name="phpcs-ci" description="Find coding standard violations using PHP_CodeSniffer creating a log file for the continuous integration server">
  <exec executable="${project.basedir}/vendor/bin/phpcs" output="/dev/null">
   <arg value="--report=checkstyle" />
   <arg value="--report-file=${project.basedir}/build/logs/checkstyle.xml" />
   <arg value="--standard=${project.basedir}/build/phpcs.xml" />
   <arg path="${project.basedir}/app" />
  </exec>
 </target>

 <target name="phpcpd" description="Find duplicate code using PHPCPD">
  <exec executable="${project.basedir}/vendor/bin/phpcpd">
   <arg value="--log-pmd" />
   <arg value="${project.basedir}/build/logs/pmd-cpd.xml" />
   <arg path="${project.basedir}/app" />
  </exec>
 </target>

 <target name="phpdox" description="Generate API documentation using phpDox">
  <exec executable="${project.basedir}/vendor/bin/phpdox"/>
 </target>

 <target name="phpunit" description="Run unit tests with PHPUnit">
  <exec executable="${project.basedir}/vendor/bin/phpunit" logoutput="true" checkreturn="1"/>
 </target>

 <target name="phpcb" description="Aggregate tool output with PHP_CodeBrowser">
  <exec executable="${project.basedir}/vendor/bin/phpcb">
   <arg value="--log" />
   <arg path="${project.basedir}/build/logs" />
   <arg value="--source" />
   <arg path="${project.basedir}/app" />
   <arg value="--output" />
   <arg path="${project.basedir}/build/code-browser" />
  </exec>
 </target>

 <target name="install" description="Prepare files and directories for Jenkins">
    <mkdir dir="./build" />
    <mkdir dir="./generatedJUnitFiles" />

    <chown file="./build" user="jenkins.jenkins" />
    <chown file="./generatedJUnitFiles" user="jenkins.jenkins" />
 </target>

</project>
4

1 回答 1

0

我想你可能没有告诉我们一些事情。您正在使用某种 SCM(bitbucket?)${project.basedir}在 ant 运行之前检查您的代码?供应商文件夹是否包含来自 SCM 的文件,或者您是否在从 SCM 下载文件后运行 composer?

您还可以chown -R jenkins:nogroup <files>用来更改文件的所有权,而不是授予所有用户对它们的完全访问权限。

编辑 (我的业力太少,无法回复评论):如果您在(virtualbox)虚拟机中设置它,而 Jenkins 只使用您的共享文件,您可能会遇到一些您可能无法使用的权限问题使用chmod或修复chown。您应该使用以下挂载命令来挂载共享文件夹:

mount -t vboxsf -o uid=${UID},gid=${GID} <shared folder> <target>

其中 ${UID} 是 jenkins 用户的 uid,${GID} 是组的组 id nogroup(通常为 65534)。

如果你使用 vagrant,你应该看看thisthis

于 2013-09-14T16:29:00.693 回答