How to update Jenkins config.xml from Java code?

前端 未结 2 1624
执笔经年
执笔经年 2021-01-26 11:37

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

2条回答
  •  情书的邮戳
    2021-01-26 12:04

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

    PFB Code

    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

    
    

    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
    

提交回复
热议问题