为什么Jenkins除了工作区之外还要挂载一个临时卷? [英] Why Jenkins mounts a temporary volume in addition to the workspace?
问题描述
我正在使用gulp
从使用dockerfile构建的映像在docker容器上运行我的js应用程序.
我是詹金斯(Jenkins)的高级初学者:).
I am using gulp
to run my js app on the docker container from an image built using a dockerfile.
I am an advanced beginner :) in Jenkins.
dockerfile
dockerfile
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命令.为简单起见,我在这里仅添加相关阶段.
jenkinsFile - I am using sequential stages. The first stage is Initialize where I am setting up the docker container. The docker image is hosted internally, I am pulling that down and running the shell commands. To keep it simple I am adding only the relevant stages here.
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
}
}
}
...
以下是构建输出中的相关部分.我已经删除了一些敏感信息.
Here are the relevant parts in the build output. I have removed some sensitive info.
...
[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附加新卷?
Why is Jenkins trying to attach a new volume with @tmp?
耐久的8c5396a6是什么?
What is durable-8c5396a6?
推荐答案
1)为什么詹金斯(Jenkins)尝试使用@tmp附加新卷?
@tmp
用于放置临时工件,例如sh
中的Shell脚本,jenkins将
创建一个包含sh
脚本的.sh
文件,然后执行此.sh
文件.
the @tmp
is used to place temp artifacts, like the Shell scriptin sh
, jenkins will
create a .sh
file which includes the script of sh
, then execute this .sh
file.
因为此.sh
文件不是源代码的一部分,所以只是阶段运行期间生成的临时文件.
Because this .sh
file is not part of your source code, just temp file generated during stages running.
您可以想到@tmp
中的文件是由Jenkins管理的,而不是由用户管理的.用户无法控制它.这是詹金斯管道设计的一部分.
You can think of the files in @tmp
are managed by Jenkins, not by user. User can't control it. It's a part of Jenkins pipeline design.
对于源代码,按使用情况管理的构建/打包工件,它们不会放置在@tmp
中,而是放置在作业工作区文件夹中,在您的情况下是/opt/jenkins/slave06/workspace/ntegrate-playground-573
,而没有@tmp
.
For source code, build/package artifact managed by use, they are not been placed in the @tmp
, but in job workspace folder, in your case is /opt/jenkins/slave06/workspace/ntegrate-playground-573
, which without the @tmp
.
2)什么是耐用型8c5396a6?
Jenkins为具有相同名称script.sh
的每个sh
生成的.sh
文件.
如果您的Jenkins文件中有多个sh
,则jenkins将script.sh
放在不同的文件夹中,以避免先前的sh
被下一个sh
Jenkins generated .sh
file for each sh
with same name script.sh
.
In case there are more than one sh
in your Jenkinsfile, jenkins put script.sh
in different folder to avoid it for previous sh
overwriten by next sh
要调试您的问题,请在./node_modules/.bin/gulp build_only
之前添加两个cmd pwd
和ls -l
.以此检查您当前的工作目录以及哪些文件&当前工作目录下的文件夹.
To debug your issue, add two cmds pwd
and ls -l
before ./node_modules/.bin/gulp build_only
. With that to check your current work dir and which files & folders under current work dir.
最可能的失败原因是您的工作目录错误,其次是gulp
未添加到项目依赖项中.
The most possible failure reason is you are in wrong work dir, secondly it's gulp
is not added into project dependencies.
这篇关于为什么Jenkins除了工作区之外还要挂载一个临时卷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!