当前位置: 首页 > 面试题库 >

为什么Jenkins除了工作区之外还要挂载一个临时卷?

司马弘益
2023-03-14
问题内容

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. 什么是耐用型8c5396a6?


问题答案:

1)为什么詹金斯试图用@tmp附加一个新的卷?

@tmp被用来代替温度工件,如壳牌scriptin sh,詹金斯将创建一个.sh文件,其中包含的脚本sh,然后执行此.sh文件。

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

您可以想到其中的文件@tmp是由Jenkins管理的,而不是由用户管理的。用户无法控制它。这是詹金斯管道设计的一部分。

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

2)什么是耐用型8c5396a6?

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

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

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



 类似资料:
  • 来自C++,我很惊讶这段代码在Rust中是有效的: 在C++中,您不能使用临时的地址,并且临时的时间不会超过它出现在其中的表达式。 临时工在铁锈中生活多长时间?而且由于只是一个借方,那么字符串的所有者是谁呢?

  • 问题内容: 在linux内核中,驱动程序提供的方法有什么作用?它与驾驶员的功能有何不同,即为什么不能在驾驶员的功能中执行功能动作? 问题答案: 不同的设备类型可以具有probe()函数。例如,PCI和USB设备都具有probe()函数。 如果您在谈论PCI设备,我建议您阅读Linux设备驱动程序的第12章,其中涵盖了驱动程序初始化的这一部分。第13章介绍了USB。 简短的回答,假设使用PCI:驱动

  • 这几天在学dart和flutter,真的发现dart和js一模一样,知道google为了取代js才有开发出了dart这个语言,但有一个问题有点不明白,google为什么要再去弄一个本来就有的语言?为了取代js弄出来dart,为了取代java弄出来golang,他们为什么要这样呢? 上面的问题有点想不明白,有懂的吗?

  • 我目前有一台装有intel i5的windows笔记本电脑。我想升级到M1 Mac。仿真对我来说不是问题(在ARM上虚拟化比较慢)。任何早期采用者能让我知道它对于基本的android开发和一些Xcode是否足够快吗?

  • 问题内容: 我们正在运行Jenkins 2.x,并且喜欢新的Pipeline插件。但是,由于存储库中有如此多的分支,因此磁盘空间会迅速填满。 是否有任何与Pipeline兼容的插件,我可以在成功构建后清除工作空间? 问题答案: 您可以将其用作管道Jenkinsfile的最后一步(假设您没有更改工作目录)。