特拉维斯:sh:0:无法打开/etc/init.d/xvfb

22

我的 Travis CI 使用 Ubuntu 14.04 和 Node.js 8。我的 .travis.yml 文件如下所示:

language: node_js
node_js:
  - 8
sudo: required
addons:
    chrome: stable
before_script:
  - export DISPLAY=:99.0
  - sh -e /etc/init.d/xvfb start
install:
  - npm set progress=false
  - npm install
script:
  - ng lint
  - npm run test
  - npm run e2e
  - npm run build

我尝试将其更新为使用Ubuntu 16.04和Node.js 10,方法是将其更改为:

language: node_js
node_js:
  - '10'
dist: xenial
sudo: required
addons:
    chrome: stable
before_script:
  - export DISPLAY=:99.0
  - sh -e /etc/init.d/xvfb start
install:
  - npm set progress=false
  - npm install
script:
  - ng lint
  - npm run test
  - npm run e2e
  - npm run build

然而现在在尝试启动xvfb时,我收到了错误提示:

0.00s$ sh -e /etc/init.d/xvfb start

sh: 0: 无法打开 /etc/init.d/xvfb

命令“sh -e /etc/init.d/xvfb start”在执行期间失败并以127退出。

2个回答

38
解答如下:

解决方案是从before_script数组中删除sh -e /etc/init.d/xvfb start,并在services数组中引入xvfb

所以我的.travis.yml现在看起来是这样的:

language: node_js
node_js:
  - '10'
dist: xenial
sudo: required
services:
  - xvfb
addons:
    chrome: stable
before_script:
  - export DISPLAY=:99.0
install:
  - npm set progress=false
  - npm install
script:
  - ng lint
  - npm run test
  - npm run e2e
  - npm run build

是的,只是忘记做了。谢谢。 - Francesco Borzi

7
除了接受的答案外,我认为结果配置应该更加清晰地符合travis文档(使用xvfb运行需要GUI的测试)。您不需要设置DISPLAY,因此before_script部分变得多余:

这仅适用于Ubuntu 16.04(Xenial)及其之后的版本,例如使用dist:xenial或dist:bionic
以下内容将启动xvfb并设置正确的DISPLAY环境变量值...

另外,在2019年的node_js中,您不需要指定dist,因为xenial现在是node_js语言的默认镜像(博客文章)。以前是trusty,因此另一个可能的解决方案可能是指定trusty作为dist(请参见文档)。但谈到默认值时,讨论的配置可能如下所示:

language: node_js
node_js:
  - '10'
sudo: required
services:
  - xvfb
addons:
    chrome: stable
install:
  - npm set progress=false
  - npm install
script:
  - ng lint
  - npm run test
  - npm run e2e
  - npm run build

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接