Hoang Pham
Hoang Pham

Reputation: 37

Jenkinsfile with building in subdirectories

So my team is trying to have a Jenkinsfile for our web development project. We have React as front-end and ExpressJS as backend. The current structure is

root
 |-- react folder
 |-- expressjs folder
 |-- jenkinsfile

Our problem is trying to build the entire project with Jenkins and we can't seem to make it work. The current Jenkinsfile is:

pipeline {
    agent {
        docker {
            image 'node:6-alpine'
        }
    }  
    stages {
        stage('Building and installing client') {
          steps {
            echo "Installing and building client"

            dir('client') {
              sh 'npm install'
              sh 'npm run-script build'
            }

            dir('server') {
              sh 'npm install'
              sh 'npm run-script test'
            }
          } 
        }
    } 
}

And this is the error message

[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Agent Setup)
[Pipeline] sh
[NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA] Running shell script
+ docker pull node:6-alpine
6-alpine: Pulling from library/node
Digest: sha256:1a5d330e7f395209c53ecb521d12519ce03a6e286bb591504a6673fc4a66b3e3
Status: Image is up to date for node:6-alpine
[Pipeline] }
[Pipeline] // stage
[Pipeline] sh
[NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA] Running shell script
+ docker inspect -f . node:6-alpine
.
[Pipeline] withDockerContainer
Jenkins seems to be running inside container a288f78860fc4087db24e0abc3ca209e5640ad67b2379bc03cd2e2ec4d8cca64
$ docker run -t -d -u 0:0 -w /var/jenkins_home/workspace/NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA --volumes-from a288f78860fc4087db24e0abc3ca209e5640ad67b2379bc03cd2e2ec4d8cca64 -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** node:6-alpine cat
$ docker top 10aff4bee7eee2346233c9edf425e6bf8b9e2f1a754d8e60ed46e5b0a1bbd001 -eo pid,comm
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Building and installing client)
[Pipeline] echo
Installing and building client
[Pipeline] dir
Running in /var/jenkins_home/workspace/NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA/client
[Pipeline] {
[Pipeline] sh
[client] Running shell script
Docker version is older than 17.12, working directory will be /var/jenkins_home/workspace/NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA not /var/jenkins_home/workspace/NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA/client
+ npm install
npm WARN enoent ENOENT: no such file or directory, open '/var/jenkins_home/workspace/NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA/package.json'
npm WARN NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA No description
npm WARN NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA No repository field.
npm WARN NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA No README data
npm WARN NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA No license field.
[Pipeline] sh
[client] Running shell script
Docker version is older than 17.12, working directory will be /var/jenkins_home/workspace/NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA not /var/jenkins_home/workspace/NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA/client
+ npm run-script build
npm ERR! Linux 4.9.77-31.58.amzn1.x86_64
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run-script" "build"
npm ERR! node v6.13.1
npm ERR! npm  v3.10.10
npm ERR! path /var/jenkins_home/workspace/NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open '/var/jenkins_home/workspace/NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA/package.json'
npm ERR! enoent ENOENT: no such file or directory, open '/var/jenkins_home/workspace/NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     /var/jenkins_home/workspace/NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA/npm-debug.log
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
$ docker stop --time=1 10aff4bee7eee2346233c9edf425e6bf8b9e2f1a754d8e60ed46e5b0a1bbd001
$ docker rm -f 10aff4bee7eee2346233c9edf425e6bf8b9e2f1a754d8e60ed46e5b0a1bbd001
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

GitHub has been notified of this commit’s build result

ERROR: script returned exit code 254
Finished: FAILURE

What should be changed in Jenkinsfile to make this 2 built in parallel?

Upvotes: 3

Views: 3034

Answers (1)

StephenKing
StephenKing

Reputation: 37600

Changing the directory inside the container (dir step) does not work in older docker versions, as Jenkins tells you:

Docker version is older than 17.12, working directory will be
/var/jenkins_home/workspace/NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA not
/var/jenkins_home/workspace/NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA/client

Upvotes: 3

Related Questions