【发布时间】:2019-03-30 12:28:14
【问题描述】:
我正在尝试使用 Jenkins Pipelines 设置自动化构建器/部署器作业。
我已经设置了一个安装 NodeJS 和 Gulp 依赖项的 docker 容器:
Dockerfile
# Node 8.9 running on lean version of alpine Linux
FROM node:8.9-alpine
# Commented out setting production since
# we need devDependencies to build
# ENV NODE_ENV production
# Set working directory to root of container
WORKDIR /
# Copy package.json and install dependencies first
# These can be cached as a step so long as they haven't changed
COPY ["./package.json", "./package-lock.json*", "/"]
RUN npm install --no-audit --silent
RUN npm install node-sass --silent
RUN npm install gulp-cli --silent
RUN npm install gulp@3.9 --silent
# Copy code to root, thise is a separate step from
# dependencies as this step will not be cached since code
# will always be different
COPY . .
# Debugging information
RUN ls
RUN pwd
RUN ./node_modules/.bin/gulp --version
Dockerfile 的目标是缓存依赖项的安装,以便构建作业运行得更快。
Jenkinsfile 使用 Dockerfile,然后尝试运行 npm 构建脚本
Jenkinsfile
pipeline {
agent {
dockerfile true
}
stages {
stage('Compile static assets') {
steps {
sh 'node --version'
sh 'npm --version'
sh 'pwd'
sh 'ls'
sh 'npm run build'
}
}
}
}
运行 Jenkins 流水线时,初始化(使用和运行 Dockerfile 的位置)似乎与步骤不匹配。 查看每个的 pwd 和 ls:
设置容器的第一步的输出
Step 9/10 : RUN ls
---> Running in 74b7483a2467
AO18_core
Jenkinsfile
bin
dev
dev_testing
etc
gulpfile.js
home
lib
media
mnt
node_modules
opt
package-lock.json
package.json
proc
root
run
sbin
srv
sys
tmp
usr
var
Removing intermediate container 74b7483a2467
---> e68a07c2bb45
Step 10/10 : RUN pwd
---> Running in 60a3a09573bc
/
编译静态资产阶段的输出
[ao_test-jenkins-YCGQYCUVORUBPWSQX4EDIRIKDJ72CXV3G5KXEDIGIY6BIVFNNVWQ] Running shell script
+ pwd
/var/lib/jenkins/workspace/ao_test-jenkins-YCGQYCUVORUBPWSQX4EDIRIKDJ72CXV3G5KXEDIGIY6BIVFNNVWQ
[ao_test-jenkins-YCGQYCUVORUBPWSQX4EDIRIKDJ72CXV3G5KXEDIGIY6BIVFNNVWQ] Running shell script
+ ls
AO18_core
Dockerfile
Jenkinsfile
README.md
dev_testing
docker-compose.debug.yml
docker-compose.yml
gulpfile.js
jsconfig.json
package.json
因此,执行上下文似乎有些我不清楚的地方。我的假设是一旦 docker 容器被初始化,整个管道就会在现有的上下文中执行。好像不是这样的。
目前我只有一个阶段,但最终会有多个阶段用于 linting、测试和部署。希望所有这些阶段都将在相同的上下文中执行。
【问题讨论】:
标签: docker jenkins jenkins-plugins jenkins-pipeline