无法打开流:Jenkins作业上的权限被拒绝错误

时间:2012-01-01 13:12:19

标签: php unix phpunit

免责声明:我的生活中从未使用过PHP。 Unix和Jenkins的新手

我在我的Ubantu系统上设置了Jenkins。 PHPUnit - 3.6.5和PHP 5.3.3

我有一个执行简单单元测试的构建文件。 当我从命令 -

执行它时,一切顺利
ant phpunit

但是当我为Jenkins工作设置同一个工作时,我会遇到异常 -

phpunit:
     [exec] PHPUnit 3.6.5 by Sebastian Bergmann.
     [exec] 
     [exec] Configuration read from /home/tarunb/Documents/Tarun/mydemo/phpunit.xml.dist
     [exec] 
     [exec] PHP Warning:  fopen(/home/tarunb/Documents/Tarun/mydemo/build/logs/junit.xml): failed to open stream: Permission denied in /usr/share/php/PHPUnit/Util/Printer.php on line 106
     [exec] PHP Stack trace:
     [exec] PHP   1. {main}() /usr/bin/phpunit:0
     [exec] PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:44
     [exec] PHP   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:125
     [exec] PHP   4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:187
     [exec] PHP   5. PHPUnit_Util_Log_JUnit->__construct() /usr/share/php/PHPUnit/TextUI/TestRunner.php:299
     [exec] PHP   6. PHPUnit_Util_Printer->__construct() /usr/share/php/PHPUnit/Util/Log/JUnit.php:141
     [exec] PHP   7. fopen() /usr/share/php/PHPUnit/Util/Printer.php:106
     [exec] .<?xml version="1.0" encoding="UTF-8"?>
     [exec] <testsuites>
     [exec]   <testsuite name="php-demo" tests="1" assertions="1" failures="0" errors="0" time="0.008163">
     [exec]     <testsuite name="MyClassTest" file="/home/tarunb/Documents/Tarun/mydemo/tests/MyClassTest.php" tests="1" assertions="1" failures="0" errors="0" time="0.008163">
     [exec]       <testcase name="testDemo" class="MyClassTest" file="/home/tarunb/Documents/Tarun/mydemo/tests/MyClassTest.php" line="7" assertions="1" time="0.008163"/>
     [exec]     </testsuite>
     [exec]   </testsuite>
     [exec] </testsuites>
     [exec] 
     [exec] 
     [exec] Time: 0 seconds, Memory: 4.50Mb
     [exec] 
     [exec] OK (1 test, 1 assertion)
     [exec] 
     [exec] Writing code coverage data to XML file, this may take a moment.PHP Warning:  DOMDocument::save(/home/tarunb/Documents/Tarun/mydemo/build/logs/clover.xml): failed to open stream: Permission denied in /usr/share/php/PHP/CodeCoverage/Report/Clover.php on line 348
     [exec] PHP Stack trace:
     [exec] PHP   1. {main}() /usr/bin/phpunit:0
     [exec] PHP 
     [exec] 
     [exec] Generating code coverage report, this may take a moment.  2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:44
     [exec] PHP   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:125
     [exec] PHP   4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:187
     [exec] PHP   5. PHP_CodeCoverage_Report_Clover->process() /usr/share/php/PHPUnit/TextUI/TestRunner.php:352
     [exec] PHP   6. DOMDocument->save() /usr/share/php/PHP/CodeCoverage/Report/Clover.php:348
     [exec] PHP Fatal error:  Uncaught exception 'RuntimeException' with message 'Could not write to /home/tarunb/Documents/Tarun/mydemo/build/coverage/index.dashboard.html.' in /usr/share/php/Text/Template.php:150

我理解当我尝试从Jenkins执行php单元测试时这是权限问题(从命令就好了)。我开始使用Jenkins作为sudo用户

sudo /etc/init.d/jenkins start

但无济于事。我错过了一些明显的事情吗?

1 个答案:

答案 0 :(得分:3)

詹金斯在默认模式下,切换到jenkins用户执行所有操作,无论你如何启动恶魔。

在文件夹上试用sudo chown -R jenkins .

对于系统范围的安装,它们位于/var/lib/jenkins/jobs/yourjob/下,但对于您来说,它似乎位于/home/tarunb/Documents/Tarun/mydemo/下。

有关如何运行Jenkins for PHP项目的更多信息,请查看:jenkins-php.orgSetting up Jenkins for PHP Projects