由于创建了@tmp路径,Jenkins Pipeline作业找不到脚本 [英] Jenkins Pipeline job can't find script due to @tmp path being created
问题描述
我正在编写一个管道作业,它将调用另一个脚本来执行. Jenkinsfile和脚本位于同一目录中,但是作业无法找到要运行的脚本.
I am writing a pipeline job that will call another script to execute. The Jenkinsfile and script exist in the same directory and yet the job fails to find the script to run.
这是脚本的相关位;
stage ('Update') {
try {
dir('jenkins/pipeline/update-jenkins-plugins-ppln') {
sh 'ls -l'
sh 'update-plugins.sh'
}
}
返回以下错误;
[update-jenkins-plugins-ppln] Running shell script
+ ls -l
total 8
-rw-r--r-- 1 jenkins jenkins 2441 Dec 20 09:34 Jenkinsfile
-rwxr-xr-x 1 jenkins jenkins 506 Dec 19 14:06 update-plugins.sh
[Pipeline] sh
[update-jenkins-plugins-ppln] Running shell script
+ update-plugins.sh
/var/lib/jenkins/workspace/update-jenkins-plugins-ppln/jenkins/pipeline/update-jenkins-plugins-ppln@tmp/durable-11cefdd0/script.sh: 2: /var/lib/jenkins/workspace/update-jenkins-plugins-ppln/jenkins/pipeline/update-jenkins-plugins-ppln@tmp/durable-11cefdd0/script.sh: update-plugins.sh: not found
如您所见,我正在使用的路径是正确的,因为根据ls
,我需要的文件update-plugins.sh
在我已路径到的目录中.但是由于某些原因,Jenkins在实际搜索脚本时会在路径上添加@tmp/durable-8d48734f/script.sh
.
As you can see, the pathing I'm using is correct because according to the ls
the file I need update-plugins.sh
is in the directory I've pathed to. For some reason though, when actually searching for the script Jenkins is adding @tmp/durable-8d48734f/script.sh
onto the path.
各种故障排除:
- 我读到即使您已经将其检出以获取Jenkinsfile,您也必须再次检出该分支,所以我是.
- 我已经缩进Jenkins框中进行检查了,是的,脚本在那里.
为什么詹金斯(Jenkins)添加@tmp位,并且有办法防止这种行为?
Why is Jenkins adding the @tmp bit, and is there a way to prevent this behavior?
推荐答案
您是否尝试过使用jenkins工作区环境变量WORKSPACE
(工作区的绝对路径)?这样,您的代码行将如下所示:
Have you tried using the jenkins workspace environment variable WORKSPACE
(absolute path of the workspace)? With that your line would look something like this:
sh '${WORKSPACE}/jenkins/pipeline/update-jenkins-plugins-ppln/update-plugins.sh'
这篇关于由于创建了@tmp路径,Jenkins Pipeline作业找不到脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!