用 groovy 在 jenkins 中编写 yaml 文件 [英] write yaml file in jenkins with groovy

查看:77
本文介绍了用 groovy 在 jenkins 中编写 yaml 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Groovy 中编写/修改 *.yaml 文件的最佳方法是什么?

What is the best way to write/modify a *.yaml file in Groovy?

我想在我的 jenkins 管道作业中修改 yaml 文件中维护的版本.使用 readYaml 我可以获取内容,但如何将其重新写回?

I would like to modify the version maintained in a yaml file within my jenkins pipeline job. With readYaml I can get the content, but how can I write it back again?

我想到的一种方法是对文件执行 sed.但我认为这不是很准确.

One way that comes to my mind would be to do a sed on the file. But I think thats not very accurate.

推荐答案

管道实用程序Steps 插件具有与 YAML 文件交互的 readYamlwriteYaml 步骤.writeYaml 默认不会覆盖你的文件,所以你必须先删除它.

The Pipeline Utility Steps plugin has the readYaml and writeYaml steps to interact with YAML files. writeYaml will not overwrite your file by default so you have to remove it first.

def filename = 'values.yaml'
def data = readYaml file: filename

// Change something in the file
data.image.tag = applicationVersion

sh "rm $filename"
writeYaml file: filename, data: data

这篇关于用 groovy 在 jenkins 中编写 yaml 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆