How to update Jenkins config.xml from Java code?

前端 未结 2 1575
执笔经年
执笔经年 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

    <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
    
    0 讨论(0)
  • 2021-01-26 12:08

    You can use the jenkins-client-api project to access Jenkins from java application. It is quite standard and definitely of great help when interacting from Java application to Jenkins. https://github.com/jenkinsci/java-client-api

    0 讨论(0)
提交回复
热议问题