【问题标题】:Travis CI NodeJs build runs locally but gets a permission denied on Travis CITravis CI NodeJs 构建在本地运行,但在 Travis CI 上获得权限被拒绝
【发布时间】:2018-07-31 16:35:13
【问题描述】:

所以当我在本地运行我的 repo 中的 mocha 测试时它工作得很好,但是当我推送一个提交并且它在 travis CI 上运行时,我不断收到这个错误:

sh: 1: mocha: Permission denied

npm ERR! Test failed.  See above for more details.

我的.travis.yml

language: node_js
node_js:
  - "6"

install:
-npm install

before_script: npm install -g mocha
before_script: chmod 0777 ./node_modules/.bin/mocha

package.json

{
  "name": "skeletonapp",
  "version": "0.0.0",
  "description": "skeletonapp",
  "main": "index.js",
  "author": {
    "name": "li"
  },
  "scripts": {
    "test": "mocha"
  },
  "dependencies": {
    "chai": "^3.5.0",
    "mocha": "^3.1.2"
  }
}

文件结构

https://travis-ci.org/LiamDotPro/Travis-CI-NodeJS-Skeleton---Mocha-Chai/builds/173340318

test.js

var assert = require('assert');
describe('Array', function () {
    describe('#indexOf()', function () {
        it('should return -1 when the value is not present', function () {
            assert.equal(-1, [1, 2, 3].indexOf(4));
        });
    });
});

【问题讨论】:

    标签: javascript node.js travis-ci


    【解决方案1】:

    开启node_modules/.bin的执行权限:https://github.com/travis-ci/travis-ci/issues/6828#issuecomment-258581083

    或者,从您的 Git 存储库中删除 node_modules,然后让 Travis 使用 npm install 安装它。 (见https://docs.travis-ci.com/user/languages/javascript-with-nodejs#Travis-CI-uses-npm。)

    【讨论】:

    • 我真的非常感谢你花时间回复我的问题,多年来一直在与这个问题作斗争。你最好!
    【解决方案2】:

    不要手动将mocha 安装到 Travis-CI。默认在这里。

    只需从.travis.yml 文件中删除您的before_script 声明即可。

    【讨论】:

    • 在主体中添加了更好的版本。
    • 可以在没有缓存的情况下重新运行测试吗?
    • 没有为任何构建设置缓存
    猜你喜欢
    • 2017-06-22
    • 2018-12-28
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多