问题
I'm trying DSL job plugin to create new jobs in Jenkins. Is there a way to specify the view when creating the job?
For example, I have a view NewJobsView
. I want to create a DSL job called dsl-job
and it is creating a new job "dsl-created-job1"
DSL like this:
job {
name 'dsl-created-job1'
//view 'NewJobsView'
//or view {...} to specify the view
}
回答1:
What if you do:
def myJob=job{name('test1')}
def myJob2=job{name('test2')}
view {
name('view1')
jobs{
name(myJob.name)
name(myJob2.name)
}
}
Or even use a regex at the view.
UPDATE
About the discussion. The nested view is just a different kind of view. The job config.xml doesn't have reference to the view because jenkins has a different abstraction: a view references to jobs.
回答2:
I got this working. It creates a job, then creates a view and adds the job to the view. This solution recreates the view every time. You can add multiple jobs using name('jobname1') or names('jobname1','jobname2'). You can also add existing jobs referencing them by name in the same manner.
job{
name('DSL JOB')
description('This is a Test Job')
triggers{
cron('H/20 7-20 * * 1-5')
}
}
view(type:ListView){
name('DSL-JOBS')
description('Test View of DSL Job')
filterBuildQueue()
filterExecutors()
jobs{
name('DSL JOB')
}
columns{
status()
weather()
name()
lastSuccess()
lastFailure()
lastDuration()
buildButton()
lastBuildConsole()
}
}
回答3:
If you just want to place the generated job in an existing view instead of having to look for it within tens of jobs and without having to recreate views each time, here is a very simple workaround:
Workaround:
- delete the job generated by your DSL
- copy (or remember) the exact name of the generated job from the DSL
- go to the view where you want the new job to reside in
- create a new empty job with the same name as the new generated job from the DSL.
- check Add to current view when saving the new empty job
- run the DSL script and it will update your existing (empty) job with the correct content while leaving it in the desired view.
You might also want to check this answer.
来源:https://stackoverflow.com/questions/22021763/create-a-job-dsl-that-creates-a-new-job-in-the-same-view