如何从Java代码更新Jenkins config.xml? [英] How to update Jenkins config.xml from Java code?

查看:470
本文介绍了如何从Java代码更新Jenkins config.xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Jenkins Plugin开发的新手,所以请问这个问题很愚蠢.我目前正在开发Jenkins插件,该插件提供了非常小的配置选项列表,如所附的屏幕截图所示.

I am new to Jenkins Plugin development so pardon me if the question is silly. I am currently developing a Jenkins Plugin that provides a very small list of configuration options as shown in the attached screenshot.

该表单是使用Jelly脚本设计的.我必须从Java代码更新作业的config.xml文件中由表单提交的这些参数.谁能在我的Java代码中建议更新作业的当前config.xml的方法吗?

The form has been designed using Jelly script. I have to update these parameters submitted by my form in the config.xml file of the job from my Java Code. Can anyone suggest the way to update the current config.xml of the job in my Java Code?

谢谢

推荐答案

经过研究,我已经知道如何通过用户定义的表单来更新配置文件.

After some research I have got to know how to update the config file through user defined form.

PFB代码

AbstractItem item= (AbstractItem) Jenkins.getInstance().getItemByFullName(itemName)
Source streamSource = new StreamSource(new StringReader(config))
item.updateByXml(streamSource);
item.save();

在果冻中,表单必须调用这样的方法

In the jelly the form has to called the method like this

<f:form method="post" name="config" action="configSubmit">

因此,要更新的代码必须按如下所示放置在方法中

So the code to update has to be placed in the method as follows

public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws
IOException, ServletException, Descriptor.FormException

这篇关于如何从Java代码更新Jenkins config.xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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