运行npm install命令时,Jenkins构建步骤失败
我正在为vue应用程序设置Jenkins构建管道。我有一个简单的Dockerfile来构建和运行VUE应用程序作为容器。当我尝试在我的PC上构建应用程序时,docker build成功完成而没有错误。
但是,一旦Jenkins构建过程启动,Dockerfile的RUN npm install
命令在构建阶段正在进行时返回错误。
我检查了服务器的交换空间,错误与此无关。手动,我在服务器上为package.json文件执行了npm安装文件。
有没有人有关于在Jenkins管道阶段执行npm命令的经验?
这是我使用的Dockerfile和Jenkinsfile
Dockerfile
# 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;"]
Jenkinsfile
#!/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
> [email protected] 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
。
还暂时尝试docker build
与--no-cache
选项,以避免由缓存层引起的任何问题。
运行npm install命令时,Jenkins构建步骤失败
我正在为vue应用程序设置Jenkins构建管道。我有一个简单的Dockerfile来构建和运行VUE应用程序作为容器。当我尝试在我的PC上构建应用程序时,docker build成功完成而没有错误。
但是,一旦Jenkins构建过程启动,Dockerfile的RUN npm install
命令在构建阶段正在进行时返回错误。
我检查了服务器的交换空间,错误与此无关。手动,我在服务器上为package.json文件执行了npm安装文件。
有没有人有关于在Jenkins管道阶段执行npm命令的经验?
这是我使用的Dockerfile和Jenkinsfile
Dockerfile
# 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;"]
Jenkinsfile
#!/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
> [email protected] 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
。
还暂时尝试docker build
与--no-cache
选项,以避免由缓存层引起的任何问题。