简体   繁体   中英

Using Jenkins Parameter In Kubernetes Yaml

I'm trying to use my Jenkins Pipeline parameter to change name in.yaml file. How can i achieve that?

In Jenkins, my parameter name is defined as NEWCLAIM

yaml file

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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