gpt4 book ai didi

Jenkinsfile 在子目录中构建

转载 作者:行者123 更新时间:2023-12-02 10:39:44 28 4
gpt4 key购买 nike

所以我的团队正在尝试为我们的 Web 开发项目创建一个 Jenkinsfile。我们以 React 作为前端,以 ExpressJS 作为后端。目前的结构是

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

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

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 中更改哪些内容才能使这两个并行构建?

最佳答案

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

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

关于Jenkinsfile 在子目录中构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49288473/

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