[英]Load YAML from file in Jenkins Pipeline
我有以下結構:
/Jenkinsfile/script2.groovy
/Jenkinsfile/pipeline2.yaml
script1.groovy
pipeline1.yaml
在 script1 中有一個對管道的引用,使用:
yamlFile "pipeline1.yml"
或者
yamlFile "./Jenkinsfiles/pipeline2.yaml"
並且工作正常。 我正在嘗試在 script2 上使用相同的管道文件,但無法使其工作。
這是腳本的相關部分:
pipeline {
agent {
kubernetes {
cloud "xxxx"
yamlFile "pipeline.yml"
}
}
任何想法?
注意: pipeline1 和 pieline2 是相同的文件,只是顯示了不同的位置。
鑒於您提到的目錄結構:
.
├── Jenkinsfile
│ ├── pipeline2.yaml
│ └── script2.groovy
├── pipeline1.yaml
└── script1.groovy
可以從其父目錄中讀取以下文件,如下所示:
對於從./
運行的script1
groovy./script1.groovy
is able to read both ./pipeline1.yaml
and ./Jenkinsfile/pipeline2.yaml
對於從./
運行的 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
能夠讀取./Jenkinfile/pipeline2.yaml
也是因為路徑是相對的。
我認為您可以通過將文件駐留在一個目錄中來簡化這一點。 並且還使用語法readYaml(file: './nameOfFile.yaml')
readyaml部分。
.
├── pipeline1.yaml
├── script1.groovy
├── pipeline2.yaml
└── script2.groovy
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.