无法打开流:Jenkins 作业上出现权限被拒绝错误
免责声明:我一生中从未使用过 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 单元测试时的权限问题(这在命令中效果很好)。我以 sudo 用户身份启动 Jenkins
sudo /etc/init.d/jenkins start
,但没有效果。我错过了一些明显的事情吗?
Disclaimer: Never used php in my life. New to Unix and Jenkins
I have set up Jenkins on my Ubantu system.
PHPUnit - 3.6.5 and PHP 5.3.3
I have a build file which execute simple unit test.
All goes well when I execute it from command like -
ant phpunit
But when I set up a job for same to be executed from Jenkins job, then I encounter exception -
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
I understand that this is permission issue when I am trying to execute php unit test from Jenkins (which works well from command like). I started Jenkins as sudo user
sudo /etc/init.d/jenkins start
but of no avail. Am I missing some thing obvious?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Jenkins 在默认模式下,无论您如何启动守护进程,都会切换到 jenkins 用户来执行所有操作。
在文件夹上尝试 sudo chown -R jenkins . 。
对于系统范围的安装,它们将位于
/var/lib/jenkins/jobs/yourjob/
下,但对于您而言,它似乎位于/home/tarunb/Documents/Tarun/mydemo/ 下
。有关如何为 PHP 项目运行 Jenkins 的更多信息,请查看:
jenkins-php.org
和设置PHP 的詹金斯项目
Jenkins, in default mode, switches to the
jenkins
user for all execution not matter how you start the demon.Try a
sudo chown -R jenkins .
on the folders.For a system wide install they would be under
/var/lib/jenkins/jobs/yourjob/
but for your side it seems to be under/home/tarunb/Documents/Tarun/mydemo/
.For further information on how to run Jenkins for PHP projects check out:
jenkins-php.org
andSetting up Jenkins for PHP Projects