Jenkins(在Docker容器中)- npm安装失败,因为... npm WARN tar ENOENT:没有这样的文件或目录,futime

11

在Jenkins Docker容器中运行“npm install”时,我收到以下错误:

[INFO] --- exec-maven-plugin:1.6.0:exec (npm install) @ geosolutions ---
npm WARN tar ENOENT: no such file or directory, open '/var/jenkins_home/workspace/aproject2/node_modules/.staging/schema-utils-bdceae78/package.json'
npm WARN tar ENOENT: no such file or directory, open '/var/jenkins_home/workspace/aproject2/node_modules/.staging/schema-utils-bdceae78/README.md'
...(and many lines like) ...
npm WARN tar ENOENT: no such file or directory, futime
npm WARN tar ENOENT: no such file or directory, futime
npm WARN tar ENOENT: no such file or directory, futime
npm WARN tar ENOENT: no such file or directory, futime
未生成“node_modules”,只有在“node_modules/.staging”下生成了一些文件。进入Jenkins Docker容器后,我可以通过手动执行以下步骤来解决这个问题:rm -rf node_modules、rm -f package-lock.json、npm install。下次我将跳过“npm install”步骤,直接开始“ng build”,然后一切正常。当然,这不是一个合适的解决方法。因此,这不是一个重复的问题。如何进行良好的“npm install”?我的Jenkins容器中有一个Node / Npm安装程序。Npm是6.5,而节点则是8、9、10或11。都带有最新的npm 6.5。我的Jenkins镜像包含用于添加npm/nodejs的代码。
RUN apt-get install -y curl \
  && curl -sL https://deb.nodesource.com/setup_9.x | bash - \
  && apt-get install -y nodejs \
  && curl -L https://www.npmjs.com/install.sh | sh

更新:今天我在办公室遇到了同样的问题。两个不同的Jenkins任务使用相同的Maven任务开始执行'npm install'命令。一个任务可以正常执行,而另一个任务则不行。其中一个Jenkins任务是通过多分支方式启动的,而另一个则是普通管道。嗯,非常奇怪。

我认为这与操作环境有关,因此与$PATH、环境变量等有关。


你尝试过这里提到的所有解决方案了吗?https://github.com/mapbox/node-sqlite3/issues/866 - rohit thomas
尝试了许多选项。尝试了可在 https://github.com/nodesource/distributions 获取的最新的nodejs/npm。我们没有收到任何sqlite错误。我已将任何新建议添加到问题中。 - tm1701
看起来你在这两个工作中都使用了相同的钩子,所以只需禁用不起作用的那个即可。 - rohit thomas
请详细说明。 - tm1701
1
老实说,我建议您将Jenkins Master作为容器运行,并使其连接到一个Jenkins Slave容器(嵌入Node)。这样,从机始终会以干净的环境开始,只包含必要的依赖项和所需的隔离级别。 - arvymetal
显示剩余2条评论
2个回答

6
经过与许多专家的交流和阅读大量论坛帖子,以下是提出的“解决方法”。许多人使用此解决方法。我希望你有比这更好的解决方案。至少,这个解决方法是有效的。
按照这个解决方法,在Maven中构建Angular可以像这样进行:首先清除工作区,特别是删除node_modules文件夹和package-lock.json文件。然后开始npm安装和构建操作。
如果在创建第一个构建后急于进行,请添加属性“maven.exec.skip”,并使用-P maven.exec.skip = true启动Maven。然后跳过清理和npm install步骤 ;-)
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
    <executions>
      <execution>
        <id>npm clear workspace</id>
        <goals>
          <goal>exec</goal>
        </goals>
        <phase>initialize</phase>
        <configuration>
          <skip>${maven.exec.skip}</skip>
          <executable>rm</executable>
          <arguments>
            <argument>-rf</argument>
            <argument>node_modules</argument>
            <argument>package-lock.json</argument>
          </arguments>
        </configuration>
      </execution>
      <execution>
        <id>npm install</id>
        <goals>
          <goal>exec</goal>
        </goals>
        <phase>initialize</phase>
        <configuration>
          <skip>${maven.exec.skip}</skip>
          <executable>npm</executable>
          <arguments>
            <argument>install</argument>
          </arguments>
        </configuration>
      </execution>
      <execution>
        <id>build Angular production code</id>
        <goals>
          <goal>exec</goal>
        </goals>
        <phase>generate-resources</phase>
        <configuration>
          <executable>npm</executable>
          <arguments>
            <argument>run</argument>
            <argument>build</argument>
            <!--<argument>&#45;&#45;prod</argument>-->
          </arguments>
        </configuration>
      </execution>
    </executions>
  </plugin>

0

面对相同的问题,解决步骤如下。

npm警告tar ENOENT:没有这样的文件或目录

解决步骤如下: I)在Jenkins作业中进入您的目录并执行

rm -rf package-lock.json

npm -i


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