Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins DSL Plugin: How to create a job in an existing jenkins View?

I found the following question regarding job creation and adding to a newly created view with the DSL plugin.

Adding job to newly created view.

How can i add a created job to an existing view with the DSL plugin? I couldn´t find any hint in the documentation. Maybe it is too obvious that i can´t see the solution?

Although i read, that creating a view will cause a re-creation if the view already exists. What means that for the existing projects under this view?

Thanks for your help.

like image 820
simon Avatar asked Aug 27 '15 16:08

simon


People also ask

What is the difference between Jenkins pipelines and the job DSL?

With Pipeline, you have features such as a parameterized manual input step, allowing you specify logic midstream within the pipeline. The logic that can be included in a Job DSL is limited to creating the jobs themselves; whereas with Pipeline you can include logic directly inside the job.

How do you create a Jenkins job and what are the types?

Go to Jenkins top page, select “New Job”, then choose “Build a free-style software project”. Now you can tell the elements of this freestyle job: Optional SCM, such as CVS or Subversion where your source code resides. Optional triggers to control when Jenkins will perform builds.


1 Answers

You can not add a job to a view that is not managed by the Job DSL. But the views managed by the DSL can contain jobs which are not managed by the DSL.

For example you can have a job called project-a which is managed manually and a job called project-b which is managed by the DSL. And a view managed by the DSL can contain both jobs.

job('project-b') {
}

listView('project-view') {
  jobs {
    name('project-a')
    name('project-b')
  }
}

It's not possible to use the Jenkins API to add a job to a view from a DSL script. The job has to exist before it can be added to a view. But when the scripts is executed, the job is not created immediately. All DSL items are created after the script has been processed.

If you do not want the manage the view with the DSL (but you should), you can try to use a filter-based view configuration. E.g. include all jobs with a name matching a regular expression. Or you can use the View Job Filters Plugin to create more complex filters.

like image 108
daspilker Avatar answered Sep 28 '22 22:09

daspilker