Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Plugin: create a new job programmatically

How to create a new Jenkins job within a plugin?

I have a Jenkins plugin that listens to a message queue and, when a message arrives, fires a new event to create a new job (or start a run).

I'm looking for something like:

Job myJob = new Job(...);

I know I can use REST API or CLI but since I'm in the plugin I'd use java internal solution.

like image 946
Emanuele Avatar asked Jan 14 '13 16:01

Emanuele


People also ask

How do I make my Jenkins job dynamic?

Jenkins Job Builder is a command-line utility that will create Jenkins jobs based upon YAML configurations. It can be installed by running the following script: Then configure the installation by creating /etc/jenkins_jobs/jenkins_jobs. ini and filling in the path to the Jenkins instance and its respective credentials.

What is Jobdsl?

Job DSL was one of the first popular plugins for Jenkins which allows managing configuration as code and many other plugins dealing with this aspect have been created since then, most notably the Jenkins Pipeline and Configuration as Code plugins.


1 Answers

Use Job DSL Plugin.

From the plugin page:

Jenkins is a wonderful system for managing builds, and people love using its UI to configure jobs. Unfortunately, as the number of jobs grows, maintaining them becomes tedious, and the paradigm of using a UI falls apart. Additionally, the common pattern in this situation is to copy jobs to create new ones, these "children" have a habit of diverging from their original "template" and consequently it becomes difficult to maintain consistency between these jobs.
The Jenkins job-dsl-plugin attempts to solve this problem by allowing jobs to be defined with the absolute minimum necessary in a programmatic form, with the help of templates that are synced with the generated jobs. The goal is for your project to be able to define all the jobs they want to be related to their project, declaring their intent for the jobs, leaving the common stuff up to a template that were defined earlier or hidden behind the DSL.
like image 51
Noel Yap Avatar answered Oct 07 '22 00:10

Noel Yap