Amudh
Amudh

Reputation: 40

Why Jenkins mounts a temporary volume in addition to the workspace?

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

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 - 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 [email protected] requires a peer of canvas@^2.5.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: 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

Questions

  1. Why is Jenkins trying to attach a new volume with @tmp?

  2. What is durable-8c5396a6?

Upvotes: 0

Views: 2132

Answers (1)

yong
yong

Reputation: 13722

1) Why is Jenkins trying to attach a new volume with @tmp?

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.

Because this .sh file is not part of your source code, just temp file generated during stages running.

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.

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) What is durable-8c5396a6?

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

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.

The most possible failure reason is you are in wrong work dir, secondly it's gulp is not added into project dependencies.

Upvotes: 4

Related Questions