Home > Software design >  Using Jenkins Parameter In Kubernetes Yaml
Using Jenkins Parameter In Kubernetes Yaml

Time:09-06

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.

CodePudding user response:

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.

  • Related