【发布时间】:2021-04-14 23:40:24
【问题描述】:
说明
我正在尝试创建一个构建映像并将其推送到注册表的 Jenkinsfile。但是我希望在推送之前,管道确保所有测试都通过。
环境
Jenkinsfile
node {
checkout scm
def customImage = docker.build("my-image:test")
customImage.inside {
dir("app"){
// chown was added to try to solve the problem with the suggested solution
// from the error log,but doesn't work.
sh 'sudo chown -R 126:133 "/.npm"'
sh 'npm run test'
}
}
}
确保应用目录,只是为了放弃这种可能性。
Dockerfile
FROM node
WORKDIR /usr/src/app
COPY app/package*.json ./
RUN npm install -D
COPY app .
EXPOSE 3000
CMD ["npm", "start"]
NPM 脚本
"scripts": {
"start": "node server.js",
"test": "NODE_ENV=test npx mocha"
},
在 podman 上运行测试
问题
当我执行 Jenkins 管道(使用多分支管道)时,我从控制台输出中收到以下错误:
由于错误建议从错误日志中添加了 chown,所以这就是我在 Jenkinsfile 中包含它的原因,尽管它不识别 sudo:
【问题讨论】: