How to programmatically add a job to a view in hudson
Asked Answered
R

2

5

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)?

Redeploy answered 6/9, 2012 at 15:38 Comment(0)
A
7

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 .

Anterior answered 27/8, 2013 at 14:16 Comment(0)
E
1

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.

Ensor answered 9/9, 2012 at 7:36 Comment(1)
I've already tried this approach. But the problem I'm facing is that this form not only requires the complete list of jobs that should be linked to the view, but also the view column configuration. And the list of colunmns to show requires knowledge of the implementation classes of the columns. If the column config is omitted then the view is empty, because no columns are shown. Additionally a jason representation of the form must be sent. If this is omitted, a status 500 code is the result. All in all this does not seem to be a practical solution.Spool

© 2022 - 2024 — McMap. All rights reserved.