繁体   English   中英

运行 npm install 命令时,Jenkins 构建步骤失败

[英]Jenkins build step fails when running npm install command

我正在为 vue 应用程序设置一个 Jenkins 构建管道。 我有一个简单的 Dockerfile 来构建和运行 VUE 应用程序作为容器。 当我尝试在我的 PC 上构建应用程序时,docker build 成功完成且没有错误。

但是,一旦 Jenkins 构建过程开始,Dockerfile 的RUN npm install命令在构建阶段进行时会返回错误。

我检查了服务器的交换空间,错误与此无关。 我手动为服务器上的 package.json 文件执行了 npm install 文件。

有没有人有在 Jenkins 管道阶段执行 npm 命令的经验?

这是我使用的 Dockerfile 和 Jenkinsfile

文件

# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

詹金斯档案

#!/usr/bin/env groovy

pipeline {
    options {
        timeout(time: 1, unit: 'HOURS')
    }

    agent none

    stages {
        stage('Pre process') {
            agent any
            steps {
                script {
                    ...
                }       
                ...               
            }
        }
        stage('Build') {
            agent any
            steps {
                sh 'docker build -t frontend'
            }
        }
        stage('Run') {
            agent any
            steps {
                sh 'docker run ..... '
            }
        }
        stage('Update') {
            agent any
            steps {
                e..
            }
        }
        stage('Test & Clean-up') {
            ....
        }
    } // stages
} // pipeline

错误信息

Step 4/10 : RUN npm install

 ---> Running in 80e0beb9442a



> node-sass@4.11.0 install /app/node_modules/node-sass

> node scripts/install.js





Service 'frontend' failed to build: The command '/bin/sh -c npm install' returned a non-zero code: 1

script returned exit code 1

不同之处可能是因为您的 Dockerfile 中没有确切的节点映像版本。 在您的 PC 和服务器上可能会有所不同。 尝试将其更改为某个固定版本,例如node:10.15.1-alpine

也暂时尝试使用--no-cache选项进行docker build以避免任何由缓存层引起的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM