简体   繁体   English

从 Jenkins 管道中的文件加载 YAML

[英]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.

相关问题 来自 YAML 文件的 Jenkins 管道 - Jenkins pipeline from YAML file 詹金斯管道从yaml读取 - Jenkins Pipeline read from yaml Jenkins - 将 Yaml 文件从管道错误部署到 Kubernetes - Jenkins - Deploy a Yaml file to Kubernetes from Pipeline Error 如何将文件中的变量加载到Jenkins管道中的Windows环境变量中? - How to load variables from file into windows environment variables in Jenkins pipeline? 当 jenkins 作业在从机上运行时,如何使用 Jenkinsfile 管道脚本从主机读取 yaml 文件? - How to read yaml file from master using Jenkinsfile pipeline script when jenkins job is running on slave machine? 如何从脚本化 jenkins 管道中读取和执行 config.yaml 文件 - How to read and execute config.yaml file from scripted jenkins pipeline 通过 jenkins 管道使用 yq 命令更新 yaml 文件 - To update a yaml file using yq command through jenkins pipeline 使用环境变量 Jenkins Pipeline 加载文件 - Load file with environment variables Jenkins Pipeline 如何使用Jenkins插件Pipeline Utility步骤中的readYAML方法在Jenkins管道中解析YAML文件 - How to parse YAML files in Jenkins pipeline using readYAML method from the Jenkins plugin Pipeline Utility Steps 在 Jenkins 管道中修改 YAML 剧本 - Modify a YAML playbook in a Jenkins pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM