Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Jenkins管道中的文件加载YAML_Jenkins_Yaml_Jenkins Pipeline_Jenkins Groovy - Fatal编程技术网

从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
用于Script2的
运行

  • 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