gpt4 book ai didi

docker - 使用Docker代理在Jenkins管道中接收 “nonexistent directory”错误

转载 作者:行者123 更新时间:2023-12-02 18:37:10 27 4
gpt4 key购买 nike

我正在使用Docker代理编写我的第一个Jenkins管道。执行管道时,在Run Docker Image阶段的日志中出现以下错误(请注意,为清楚起见已删除了管道步骤):

sh: can't create /data/jenkins/workspace/my-workspace@tmp/durable-01234567/pid: nonexistent directory

Jenkins ·洛格(Jenkins Log)
Started by user Doug R.
> git rev-parse --is-inside-work-tree # timeout=10
Setting origin to http://my-git.example.com/scm/im/my-project.git
> git config remote.origin.url http://my-git.example.com/scm/im/my-project.git # timeout=10
Fetching origin...
Fetching upstream changes from origin
> git --version # timeout=10
> git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/*
Seen branch in repository origin/master
Seen 1 remote branch
Obtained Jenkinsfile from 01234567890abcdef01234567890abcdef
Running in Durability level: MAX_SURVIVABILITY
Running on Jenkins in /data/jenkins/workspace/my-workspace
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url http://my-git.example.com/scm/im/my-project.git # timeout=10
Fetching without tags
Fetching upstream changes from http://my-git.example.com/scm/im/my-project.git
> git --version # timeout=10
> git fetch --no-tags --progress http://my-git.example.com/scm/im/my-project.git +refs/heads/*:refs/remotes/origin/*
Checking out Revision 01234567890abcdef01234567890abcdef (master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 01234567890abcdef01234567890abcdef
Commit message: "Yet another test"
> git rev-list --no-walk 01234567890abcdef01234567890abcdef # timeout=10
[WS-CLEANUP] Deleting project workspace...[WS-CLEANUP] done
Cloning the remote Git repository
Cloning with configured refspecs honoured and without tags
Cloning repository http://my-git.example.com/scm/im/my-project.git
> git init /data/jenkins/workspace/my-workspace # timeout=10
Fetching upstream changes from http://my-git.example.com/scm/im/my-project.git
> git --version # timeout=10
> git fetch --no-tags --progress http://my-git.example.com/scm/im/my-project.git +refs/heads/*:refs/remotes/origin/*
> git config remote.origin.url http://my-git.example.com/scm/im/my-project.git # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url http://my-git.example.com/scm/im/my-project.git # timeout=10
Fetching without tags
Fetching upstream changes from http://my-git.example.com/scm/im/my-project.git
> git fetch --no-tags --progress http://my-git.example.com/scm/im/my-project.git +refs/heads/*:refs/remotes/origin/*
Checking out Revision 01234567890abcdef01234567890abcdef (master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 01234567890abcdef01234567890abcdef
Commit message: "Running without reuseNode true"
Running on Jenkins in /data/jenkins/workspace/my-workspace@2
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url http://my-git.example.com/scm/im/my-project.git # timeout=10
Fetching without tags
Fetching upstream changes from http://my-git.example.com/scm/im/my-project.git
> git --version # timeout=10
> git fetch --no-tags --progress http://my-git.example.com/scm/im/my-project.git +refs/heads/*:refs/remotes/origin/*
Checking out Revision 01234567890abcdef01234567890abcdef (master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 01234567890abcdef01234567890abcdef
Commit message: "Running without reuseNode true"
Wrote authentication to /root/.docker/config.json
[my-workspace@2] Running shell script
+ docker inspect -f . alpine:3.8
.
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 0:0 -w /data/jenkins/workspace/my-workspace@2 -v /data/jenkins/workspace/my-workspace@2:/data/jenkins/workspace/my-workspace@2:rw,z -v /data/jenkins/workspace/my-workspace@2@tmp:/data/jenkins/workspace/my-workspace@2@tmp:rw,z -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 ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat alpine:3.8
[my-workspace@2] Running shell script
sh: can't create /data/jenkins/workspace/my-workspace@2@tmp/durable-0123457/pid: nonexistent directory
sh: can't create /data/jenkins/workspace/my-workspace@2@tmp/durable-0123457/jenkins-log.txt: nonexistent directory
sh: can't create /data/jenkins/workspace/my-workspace@2@tmp/durable-0123457/jenkins-result.txt: nonexistent directory
$ docker stop --time=1 01234567890abcdef01234567890abcdef01234567890abcdef01234567890abcdef
$ docker rm -f 01234567890abcdef01234567890abcdef01234567890abcdef01234567890abcdef
ERROR: script returned exit code -2
Finished: FAILURE

Jenkins 文件

根据我的判断,Jenkinsfile似乎写得正确,但我敢肯定不是。
import groovy.json.*
pipeline {

environment {
COMPOSE_TLS_VERSION = "TLSv1_2"
DOCKER_TLS_VERIFY = 1
DOCKER_CERT_PATH = "/opt/ucp"
DOCKER_HOST = "tcp://my-docker-host.example.com:443"
}

agent any
stages {
stage('Prepare Workspace') {
steps {
script {
step([$class: 'WsCleanup'])
checkout scm
}
}
}

stage('Run Docker Image') {
agent {
docker {
reuseNode true
image 'alpine:3.8'
registryUrl 'https://my-docker-registry.example.com'
registryCredentialsId 'my-docker-credentials'
}
}
steps {
sh 'ls -la'
sh 'printenv'
}
}
}
}

更新资料

我找到了这个链接,它讨论了 Docker-in-Docker场景,但是我没有运行Docker-in-Docker。

最佳答案

我的问题有不同的根本原因,但与Docker-in-Docker相同(见上文)。

在我的情况下,Jenkins在不同于Jenkins所在的节点上运行docker镜像,因此它无法访问我的工作区目录。因此,本文中确定的解决方案也可能会起作用:

One way to make it work is to have the agent workspace shared from the host, in your case using /jenkins/workspace as a volume in the agent so the data written by the agent is actually written in the host and then can be shared to the new container. You can also change the workspace location in the agent definition to something else than the default jenkins.



但是,我没有执行此操作所需的特权,因此我目前正在使用一种构建临时镜像的解决方法,然后在其中执行构建的那一部分。虽然这对我来说适用,但不太可能在所有情况下都适用。

关于docker - 使用Docker代理在Jenkins管道中接收 “nonexistent directory”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54077682/

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