从Jenkins管道中的文件加载YAML
我的结构如下:从Jenkins管道中的文件加载YAML,jenkins,yaml,jenkins-pipeline,jenkins-groovy,Jenkins,Yaml,Jenkins Pipeline,Jenkins Groovy,我的结构如下: /Jenkinsfile/script2.groovy /Jenkinsfile/pipeline2.yaml script1.groovy pipeline1.yaml script1中有一个对管道的引用,使用: yamlFile "pipeline1.yml" 或 而且效果很好。我试图在script2上使用相同的管道文件,但无法使其工作 以下是脚本的相关部分: pipeline { agent { kubernetes {
/Jenkinsfile/script2.groovy
/Jenkinsfile/pipeline2.yaml
script1.groovy
pipeline1.yaml
script1中有一个对管道的引用,使用:
yamlFile "pipeline1.yml"
或
而且效果很好。我试图在script2上使用相同的管道文件,但无法使其工作
以下是脚本的相关部分:
pipeline {
agent {
kubernetes {
cloud "xxxx"
yamlFile "pipeline.yml"
}
}
有什么想法吗
注意:pipeline1和pieline2是相同的文件,只是显示了不同的位置。鉴于您提到的目录结构:
。
├── 詹金斯档案
│ ├── 管道2.yaml
│ └── script2.groovy
├── 管道1.yaml
└── script1.groovy
可以从其父目录中读取以下文件,如下所示:
对于script1从/
能够同时读取groovy./script1.groovy
和/pipeline1.yaml
/Jenkinsfile/pipeline2.yaml
运行
groovy./Jenkinsfile/script2.groovy
能够读取/pipeline1.yaml
,因为它在同一目录下,文件/Jenkinsfile/script2.groovy
是从运行的,即/
groovy./Jenkinsfile/script2.groovy
能够读取/Jenkinsfile/pipeline2.yaml
,这也是因为路径是相对的
我认为您可以通过将文件驻留在一个目录中来简化这一过程。还可以使用语法readYaml(文件:'./nameOfFile.yaml')
部分
似乎不起作用,也许是詹金斯如何运行脚本?
pipeline {
agent {
kubernetes {
cloud "xxxx"
yamlFile "pipeline.yml"
}
}
.
├── pipeline1.yaml
├── script1.groovy
├── pipeline2.yaml
└── script2.groovy