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

查看:739
本文介绍了用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.

推荐答案

管道实用程序步骤 插件具有用于与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天全站免登陆