简体   繁体   English

在 Kubernetes Yaml 中使用 Jenkins 参数

[英]Using Jenkins Parameter In Kubernetes Yaml

I'm trying to use my Jenkins Pipeline parameter to change name in.yaml file.我正在尝试使用我的 Jenkins 管道参数来更改 .yaml 文件中的名称。 How can i achieve that?我怎样才能做到这一点?

In Jenkins, my parameter name is defined as NEWCLAIM在 Jenkins 中,我的参数名称定义为NEWCLAIM

yaml file yaml 文件

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: ${params.NEWCLAIM}
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

I get errors when i use like that.当我这样使用时会出错。

In Jenkins you can use readYaml and writeYaml for that.If you use a scripted pipeline aka a Jenkinsfile, I would do the following:在 Jenkins 中,您可以为此使用readYamlwriteYaml 。如果您使用脚本化管道,也就是 Jenkinsfile,我会执行以下操作:

pipeline {
   stages {
      stage('Manipulate Yaml file') {
         def config = readYaml file: "path/to/your/config.yml"
         config.metadata.name = params.NEWCLAIM
         writeYaml file: "path/to/your/config.yml", data: config
      }
   }
}

Please consider to set permissions correctly in order to write the file.请考虑正确设置权限以便写入文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM