我gulp用来从使用dockerfile构建的映像在docker容器上运行我的js应用程序。我是詹金斯(Jenkins)的高级初学者:)。
gulp
docker文件
FROM node:10.11.0-alpine RUN apk update && apk add --no-cache git curl python py-pip bzip2 alpine-sdk && \ pip install --upgrade awscli && \ rm -rf /tmp/* /var/lib/apt/lists/* /var/cache/apk/* WORKDIR /app COPY . . ADD . /usr/src/app/. RUN chmod -R 777 /usr/src/app WORKDIR /usr/src/app
jenkinsFile- 我正在使用顺序阶段。第一阶段是初始化,我在这里设置docker容器。docker映像在内部托管,我将其下拉并运行shell命令。为简单起见,我仅在此处添加相关阶段。
pipeline { agent none options { timeout(time: timeoutSeconds, unit: 'SECONDS') disableConcurrentBuilds() } stage('Initialize') { agent { docker { image 'js-docker-image' registryUrl 'https://my-artifactory-url' registryCredentialsId artifactoryCredentialsId args '-u root -v /var/run/docker.sock:/var/run/docker.sock' label 'docker' } } stages { stage('Install Dependencies') { steps { script { def command = ''' npm install ''' sh command } } } stage('Build') { steps { script { def command = ''' ./node_modules/.bin/gulp build_only ''' sh command } } } ...
以下是构建输出中的相关部分。我已删除一些敏感信息。
... [Pipeline] { [Pipeline] stage [Pipeline] { (Initialize) [Pipeline] node Running on slave06 in /opt/jenkins/slave06/workspace/ntegrate-playground-573 [Pipeline] { [Pipeline] checkout ... $ docker run -t -d -u 133733063:133693953 -u root -v /var/run/docker.sock:/var/run/docker.sock -w /opt/jenkins/slave06/workspace/ntegrate-playground-573 -v /opt/jenkins/slave06/workspace/ntegrate-playground-573:/opt/jenkins/slave06/workspace/ntegrate-playground-573:rw,z -v /opt/jenkins/slave06/workspace/ntegrate-playground-573@tmp:/opt/jenkins/slave06/workspace/ntegrate-playground-573@tmp:rw,z -e ******** docker-internal-registry/js-docker-image:latest cat ... ... $ docker top f6cddf731de8cd63c37e12462f1041db2f4a14486ad98e00dbb81d210711bc63 + npm install npm WARN jsdom@15.2.1 requires a peer of canvas@^2.5.0 but none is installed. You must install peer dependencies yourself. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) audited 901232 packages in 20.046s found 16 vulnerabilities (4 low, 1 moderate, 11 high) run `npm audit fix` to fix them, or `npm audit` for details [Pipeline] } [Pipeline] // script [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Build) [Pipeline] script [Pipeline] { [Pipeline] sh + ./node_modules/.bin/gulp build_only /opt/jenkins/slave06/workspace/ntegrate-playground-573@tmp/durable-8c5396a6/script.sh: line 1: ./node_modules/.bin/gulp: not found
问题
Jenkins为什么尝试使用@tmp附加新卷?
什么是耐用型8c5396a6?
1)为什么詹金斯试图用@tmp附加一个新的卷?
将@tmp被用来代替温度工件,如壳牌scriptin sh,詹金斯将创建一个.sh文件,其中包含的脚本sh,然后执行此.sh文件。
@tmp
sh
.sh
因为此.sh文件不是源代码的一部分,所以只是阶段运行期间生成的临时文件。
您可以想到其中的文件@tmp是由Jenkins管理的,而不是由用户管理的。用户无法控制它。这是詹金斯管道设计的一部分。
对于源代码,按使用管理的构建/打包工件不会放置在中@tmp,而是放置在工作区文件夹中(在您的情况下是)/opt/jenkins/slave06/workspace/ntegrate- playground-573,而没有@tmp。
/opt/jenkins/slave06/workspace/ntegrate- playground-573
2)什么是耐用型8c5396a6?
Jenkins .sh为每个sh具有相同名称的文件生成文件script.sh。如果sh您的Jenkins script.sh文件中有多个,则jenkins放在不同的文件夹中,以避免先前的内容sh被下一个覆盖sh
script.sh
要调试您的问题 ,添加两个CMDS pwd和ls -l之前./node_modules/.bin/gulp build_only。用它来检查您当前的工作目录以及当前工作目录下的文件和文件夹。
pwd
ls -l
./node_modules/.bin/gulp build_only
最可能的失败原因是您的工作目录错误,其次它gulp没有添加到项目依赖项中。