簡體   English   中英

在 Kubernetes Yaml 中使用 Jenkins 參數

[英]Using Jenkins Parameter In Kubernetes Yaml

我正在嘗試使用我的 Jenkins 管道參數來更改 .yaml 文件中的名稱。 我怎樣才能做到這一點?

在 Jenkins 中,我的參數名稱定義為NEWCLAIM

yaml 文件

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

當我這樣使用時會出錯。

在 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
      }
   }
}

請考慮正確設置權限以便寫入文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM