[英]Unable to change a directory inside a Docker container through a Jenkins declarative pipeline
I'm trying to change the current directory using the dir
command outlined here: https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#code-dir-code-change-current-directory 我正在尝试使用此处概述的
dir
命令更改当前目录: https : //jenkins.io/doc/pipeline/steps/workflow-basic-steps/#code-dir-code-change-current-directory
I've edited my pipeline to resemble something like this: 我编辑了我的管道,就像这样:
pipeline {
agent { dockerfile true }
stages {
stage('Change working directory...') {
steps {
dir('/var/www/html/community-edition') {
sh 'pwd'
}
}
}
}
}
It doesn't change the directory at all but instead tries to create a directory on the host and fails with java.io.IOException: Failed to mkdirs: /var/www/html/community-edition
它根本不会更改目录,而是尝试在主机上创建一个目录并使用
java.io.IOException: Failed to mkdirs: /var/www/html/community-edition
Using sh cd /var/www/html/community-edition
doesn't seem to work either. 使用
sh cd /var/www/html/community-edition
似乎也不起作用。 How do I change the directory in the container? 如何更改容器中的目录? Someone else seems to have had the same issue but had to change his pipeline structure to change the directory and doesn't sound like a reasonable fix.
其他人似乎有同样的问题,但不得不改变他的管道结构来改变目录,听起来不是一个合理的修复。 Isn't the step already being invoked in the container?
是不是已经在容器中调用了步骤? https://issues.jenkins-ci.org/browse/JENKINS-46636
https://issues.jenkins-ci.org/browse/JENKINS-46636
I had the same problem yesterday. 我昨天遇到了同样的问题。 It seems to be a bug that causes
dir()
not to change the directory when used inside a container. 这似乎是一个错误导致
dir()
在容器内使用时不更改目录。 I've got it to work by executing the cd
and pwd
command at once, like this: 我通过一次执行
cd
和pwd
命令让它工作,像这样:
sh '(cd //var/www/html/community-edition && pwd)'
I had same issue and this worked for me when I had "ws" in jenkinsfile pipeline: 我有同样的问题,当我在jenkinsfile管道中有“ws”时,这对我有用:
stage('prepare') {
steps {
ws('/var/jenkins_home/workspace/pipeline@script/desiredDir') {
sh ''
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.