How to programmatically add a job to a view in hudson

元气小坏坏 提交于 2019-12-10 17:15:17

问题


I have a Java program controlling automatically generated jobs for a set of hudson servers. It is no problem to create, delete or update job(config)s using the hudson remote API. I also managed it to create hudson views and to create a new job for a hudson view. But I still need to know how to add an already existing job to a view and how to remove it again.

Are there URLs with arguments doing the job (like for the job creation)?


回答1:


You can execute a groovy script through the Hudson CLI API that will add a job to a view. Here is the code:

import hudson.model.*

def job = Hudson.instance.getView("View").getItem("Job")
Hudson.instance.getView("View2").add(job)

and the command for the CLI is:

java -jar hudson-cli.jar -s http://`your-hudson-server` groovy myScript.groovy

Note that you must have Groovy support plugin installed on your Hudson instance in order to execute the script. You can install it on: http://your-hudson-server/pluginManager .




回答2:


There is no api for view configuration (at least not in Jenkins v1.424.6), but it should be possible to add a job to view foo by using the form at http://[jenkins-host]/view/foo/configure (submitting to http://[jenkins]/view/foo/configSubmit).

If you are using Java, HTMLUnit or HttpClient of Apache HttpComponents can help you with this.



来源:https://stackoverflow.com/questions/12303629/how-to-programmatically-add-a-job-to-a-view-in-hudson

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!