Jenkinsfile与子目录中的建设

时间:2018-03-14 22:15:32

标签: jenkins jenkins-pipeline

所以我的团队正在尝试为我们的Web开发项目安装Jenkins文件。我们将React作为前端,将ExpressJS作为后端。目前的结构是

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

我们的问题是尝试使用Jenkins构建整个项目,我们似乎无法使其工作。目前的Jenkins文件是:

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'
            }
          } 
        }
    } 
}

这是错误消息

[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

在Jenkinsfile中应该改变什么来使这个2并行构建?

1 个答案:

答案 0 :(得分:2)

更改容器内的目录(dir步骤)在旧的docker版本中不起作用,正如Jenkins告诉你的那样:

  

泊坞版本比17.12老,工作目录将被
的/ var / jenkins_home /工作区/ NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA不
的/ var / jenkins_home /工作区/ NodeJS_Pipeline_master-IQYFYMURLJWAD3NRZOFQPKSLNREQZAIX2CTF2PGCRVEQI6PNF6GA /客户端