簡體   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