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

tm1*_*701 8 npm jenkins docker

在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
Run Code Online (Sandbox Code Playgroud)

没有生成'node_modules'.node_modules/.staging中只有少数几个.

进入Jenkins Docker容器时,我可以通过手动执行以下操作来解决此问题:

  • rm -rf node_modules
  • rm -f package-lock.json
  • npm安装

下次我必须跳过'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
Run Code Online (Sandbox Code Playgroud)

更新:今天我在办公室遇到了同样的问题.两个不同的Jenkinsjobs使用'npm install'启动完全相同的Maven任务.一个是好的,另一个没有.一个Jenkinsjob通过多分支启动,另一个作为常规管道启动.嗯,很奇怪.

我认为这与操作环境有关,所以$ PATH,环境变量等等.

tm1*_*701 6

在与一些专家交谈并阅读了大量论坛帖子之后,以下是提议的"解决方法".很多人都使用这种解决方法.我希望你有一个比这个更好的解决方案.至少,这种解决方法有效.

解决方法之后,在Maven中构建Angular可以像这样:首先清除工作区,特别是删除node_modules文件夹和package-lock.json文件.然后启动npm install和构建操作.

如果您在创建第一个构建后匆忙,只需添加属性"maven.exec.skip",然后使用-P maven.exec.skip = true启动Maven.然后跳过清理和npm安装步骤;-)

<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>
Run Code Online (Sandbox Code Playgroud)