【问题标题】:yarn install for repositories with git+https not working in Jenkins使用 git+https 为存储库安装纱线在 Jenkins 中不起作用
【发布时间】:2018-08-02 06:25:59
【问题描述】:

我正在尝试在 Jenkins 上配置我的项目,以便每次提交都会导致自动构建。 当我使用 Jenkins NodeJS 脚本运行 yarn install 时,它拒绝安装从 git 存储库导入的依赖项。我正在按照以下方式进行操作。

"some-component": "git+https://bitbucket.org/owner/repo.git"

它显示以下错误:

error Command failed.
Exit code: 128
Command: git
Arguments: clone git+https://bitbucket.org/owner/repo.git
Output:
fatal: destination path 'some path' already exists and is not an empty directory.
error Command failed with exit code 1.

如果文件为空,则显示以下错误

error Couldn't find the binary git
error Command failed with exit code 1.

虽然相同的 yarn install 在 IDE 上完美运行,例如VS 代码。

我正在使用以下代码在 Jenkins 上的 NodeJS 脚本中执行 yarn install

var exec = require('child_process').exec,
    child;

 child = exec('yarn install ',
 function (error, stdout, stderr) {
     console.log('stdout: ' + stdout);
     console.log('stderr: ' + stderr);
     if (error !== null) {
          console.log('exec error: ' + error);
     }
 });

【问题讨论】:

    标签: node.js reactjs jenkins npm yarnpkg


    【解决方案1】:

    我在 docker 容器中尝试从 git 存储库添加包时收到相同的错误。

    $ yarn add git+https://git@github.com/username/some_repo.git
    error Couldn't find the binary git
    info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
    

    我认为 yarn 试图解析我使用的 url 存在问题;您可以使用不同的变体(例如 https、git+https、ssh)。 过来发现,我所在的docker容器,没有安装git。 因此,当 yarn 的任务是尝试检索 git 存储库时,它没有 git 二进制文件来执行此操作。

    解决方法:在docker容器中安装git

    希望即使我的解决方案的上下文不同(我在 docker 容器中,而不是在 Jenkins 工作中),如果您确保在您的 Jenkins 工作中可以访问 git,它可能有助于解决您的问题。

    您可以通过运行git --version 来测试它,并且应该有一个版本输出证明您有或没有可用的 git。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 2018-11-29
      • 1970-01-01
      • 2020-09-03
      相关资源
      最近更新 更多