[英]Load YAML from file in Jenkins Pipeline
I have the following structure:我有以下结构:
/Jenkinsfile/script2.groovy
/Jenkinsfile/pipeline2.yaml
script1.groovy
pipeline1.yaml
There's a reference in script1 to the pipeline using:在 script1 中有一个对管道的引用,使用:
yamlFile "pipeline1.yml"
or或者
yamlFile "./Jenkinsfiles/pipeline2.yaml"
And works fine.并且工作正常。 I'm trying to use the same pipeline file on script2 but can't make it work.
我正在尝试在 script2 上使用相同的管道文件,但无法使其工作。
Here's the relevant part of the script:这是脚本的相关部分:
pipeline {
agent {
kubernetes {
cloud "xxxx"
yamlFile "pipeline.yml"
}
}
Any idea?任何想法?
Note: pipeline1 and pieline2 are the same files just showing different locations.注意: pipeline1 和 pieline2 是相同的文件,只是显示了不同的位置。
Given the directory structure you mentioned:鉴于您提到的目录结构:
.
├── Jenkinsfile
│ ├── pipeline2.yaml
│ └── script2.groovy
├── pipeline1.yaml
└── script1.groovy
The following files can be read from within their parent directory as follows:可以从其父目录中读取以下文件,如下所示:
For script1 ran from ./
对于从
./
运行的script1
groovy./script1.groovy
is able to read both ./pipeline1.yaml
and ./Jenkinsfile/pipeline2.yaml
groovy./script1.groovy
is able to read both ./pipeline1.yaml
and ./Jenkinsfile/pipeline2.yaml
For Script2 ran from ./
对于从
./
运行的 Script2
groovy./Jenkinsfile/script2.groovy
is able to read ./pipeline1.yaml
, since its in the same directory the file ./Jenkinsfile/script2.groovy
is being run from ie ./
groovy./Jenkinsfile/script2.groovy
is able to read ./pipeline1.yaml
, since its in the same directory the file ./Jenkinsfile/script2.groovy
is being run from ie ./
groovy./Jenkinsfile/script2.groovy
is able to read ./Jenkinfile/pipeline2.yaml
also because the path is relative. groovy./Jenkinsfile/script2.groovy
能够读取./Jenkinfile/pipeline2.yaml
也是因为路径是相对的。
I think you could possibly simplify this by just having the files reside in one directory.我认为您可以通过将文件驻留在一个目录中来简化这一点。 And also using the syntax
readYaml(file: './nameOfFile.yaml')
readyaml section.并且还使用语法
readYaml(file: './nameOfFile.yaml')
readyaml部分。
.
├── pipeline1.yaml
├── script1.groovy
├── pipeline2.yaml
└── script2.groovy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.