gpt4 book ai didi

node.js - 为什么 Jenkins 除了工作区之外还要挂载临时卷?

转载 作者:太空宇宙 更新时间:2023-11-04 03:14:09 24 4
gpt4 key购买 nike

我正在使用 gulp 从使用 dockerfile 构建的镜像在 docker 容器上运行我的 js 应用程序。我是 Jenkins 的高级初学者:)。

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

问题

  1. 为什么 Jenkins 尝试使用 @tmp 附加新卷?

  2. 什么是 Durable-8c5396a6?

最佳答案

1) 为什么 Jenkins 尝试使用 @tmp 附加新卷?

@tmp 用于放置临时工件,例如 sh 中的 Shell 脚本,jenkins 会创建一个包含sh脚本的.sh文件,然后执行该.sh文件。

因为这个.sh文件不是源代码的一部分,只是阶段运行期间生成的临时文件。

你可以认为@tmp中的文件是由Jenkins管理的,而不是由用户管理的。用户无法控制它。它是 Jenkins 管道设计的一部分。

对于由使用管理的源代码、构建/打包工件,它们不会放置在 @tmp 中,而是放置在作业工作区文件夹中,在您的情况下是 /opt/jenkins/slave06/workspace/ntegrate-playground-573,其中没有 @tmp

2) 耐用-8c5396a6 是什么?

Jenkins 为每个具有相同名称 script.shsh 文件生成了 .sh 文件。如果您的 Jenkinsfile 中有多个 sh,jenkins 将 script.sh 放在不同的文件夹中,以避免前一个 sh 被下一个 sh 覆盖

要调试您的问题,请在 ./node_modules/.bin/gulp build_only 之前添加两个命令 pwdls -l。用它来检查您当前的工作目录以及当前工作目录下的文件和文件夹。

最可能的失败原因是你工作目录错误,其次是gulp没有添加到项目依赖项中。

关于node.js - 为什么 Jenkins 除了工作区之外还要挂载临时卷?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59220020/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com