我们最终采用的解决方案很像 Jakub 建议的 - 我们的 Jenkins 实例在 conf.d 中为每个使用 Behat 的工作区生成 Apache vhost 文件,使用类似以下的脚本:
# Set up a host file entry if none exists
hostFileEntry="127.0.0.1 ${JOB_NAME}.loc"
if fgrep -i "$hostFileEntry" /etc/hosts
then
echo "${hostFileEntry}" already in hosts file
else
echo $hostFileEntry >> /etc/hosts
fi
# Set up a virtual host for this job
echo "<VirtualHost *:80>" > /etc/httpd/conf.d/${JOB_NAME}.conf
echo " ServerName ${JOB_NAME}.loc" >> /etc/httpd/conf.d/${JOB_NAME}.conf
echo " DocumentRoot ${WORKSPACE}/public" >> /etc/httpd/conf.d/${JOB_NAME}.conf
echo " <Directory ${WORKSPACE}/public>" >> /etc/httpd/conf.d/${JOB_NAME}.conf
echo " AllowOverride all" >> /etc/httpd/conf.d/${JOB_NAME}.conf
echo " Order allow,deny" >> /etc/httpd/conf.d/${JOB_NAME}.conf
echo " Allow from all" >> /etc/httpd/conf.d/${JOB_NAME}.conf
echo " </Directory>" >> /etc/httpd/conf.d/${JOB_NAME}.conf
echo "</VirtualHost>" >> /etc/httpd/conf.d/${JOB_NAME}.conf
# Reload Apache
sudo /sbin/service httpd reload
然后,我们针对这些工作区运行 Behat 并以 JUnit 格式输出,以将结果与我们的构建集成。它需要对权限进行一些调整,但这对我们来说非常有效,非常感谢您的帮助:-)