Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a Job DSL that creates a new job in the same View

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
}
like image 712
Aimee Avatar asked Oct 02 '22 12:10

Aimee


2 Answers

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.

like image 80
nerdioculos Avatar answered Oct 12 '22 10:10

nerdioculos


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()
    }
}
like image 28
moglimcgrath Avatar answered Oct 12 '22 09:10

moglimcgrath