我正在为Vue应用程序建立一个Jenkins构建管道。我有一个简单的Dockerfile来将VUE应用程序构建和运行为容器。当我尝试在PC上构建应用程序时,docker构建成功完成而没有错误。
但是,一旦Jenkins构建过程开始,则在构建阶段进行过程中,Dockerfile的RUN npm install
命令将返回错误。
我检查了服务器的交换空间,该错误与此无关。手动地,我在服务器上为package.json文件执行了一个npm安装文件。
有人在詹金斯管线阶段执行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
> 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
答案 0 :(得分:1)
差异可能是因为Dockerfile中没有确切的节点映像版本。在您的PC和服务器上可能有所不同。尝试将其更改为某个固定版本,例如node:10.15.1-alpine
。
还可以暂时尝试使用docker build
选项和--no-cache
来避免由缓存层引起的任何问题。