Database (2024)

This library plugin defines a common abstraction to connect to relational database. By doing so, it serves three purposes:

  • It allows database driver plugins (such as H2 Database Plugin) to be developed, improving the user experience for administrators.
  • It simplifies other plugins that use RDBMS by eliminating the need to code up a configuration UI to let administrators select database.

This plugin is not meant to be used by end users by itself. It's supposed to be included through the dependencies of other plugins. If you are wondering how to store your job configuration etc. in a database, the answer is that you cannot.

Usage

The key class in this plugin is the Database class, which acts as a holder for JDBC DataSource instance. The Database class is an extension point to be implemented by database driver plugins.

The calling code can use this DataSource instance to obtain a connection to the database.

Use the Jenkins global database

This plugin adds a system configuration entry to let the administrator configure the database used by Jenkins to store miscellaneous stuff. So the easiest way for plugins to start storing data to the database is to use this Database instance. This global database instance is kept in the GlobalDatabaseConfiguration class. You can inject this via @Inject, or you can call GlobalDatabaseConfiguration.get() to retrieve it, and then use the getDatabase() method to obtain the Database instance.

Because the database is shared by all the plugins, please use table names that include your plugin name as a prefix to avoid collisions.

Use the per-job database

In addition to the global database, this plugin also creates a database local to TopLevelItem. These databases are normally backed by embedded database that stores data under $JENKINS_HOME/jobs/NAME, and this simplifies the backup, copying, deletion of the data that's local to jobs (such as test reports, coverage data, and so on.)

This information is kept in the PerItemDatabase class, which you can obtain by PerItemDatabaseConfiguration.findOrNull().

Your own database

Sometimes it makes sense to store data to an entirely different database. Users may already have a database with data in it, in which case he'd want to just connect to that.

A plugin that wants to do this should define a field whose type is Database (see example). In the config.{groovy,jelly}, use the f:dropdownDescriptorSelector tag to allow the user to select a database (see example).

JPA support

This plugin exposes it through JPA 2.0 API (internally, it uses Hibernate but please do not rely on this fact if you can as it may change.) The entry point to the JPA support is the PersistenceService class, and this exposes methods for obtaining EntityManagerFactory for both the global database as well as arbitrary per-item database of your choice.

Because there are several different databases, involved, @Entity annotation alone is not sufficient. For persisted classes meant for the global database, please put @GlobalTable in addition to @Entity.

The following code shows how to use this to persiste a new row:

public class Push { @Inject PersistenceService ps; public void go(int n) throws IOException, SQLException { Jenkins.getInstance().getInjector().injectMembers(this); EntityManager em = ps.getGlobalEntityManagerFactory().createEntityManager(); em.getTransaction().begin(); TestRow row = new TestRow(); row.buildNumber = n; row.x = "foo"; em.persist(row); em.getTransaction().commit(); em.close(); }}@GlobalTable@Entitypublic class TestRow { @Id @Column public int buildNumber; @Column public String x;}

Developing driver plugin

MySQL Database plugin and PostgreSQL Database plugin are good examples of typical database driver plugins. For other "unusual" drivers that doesn't use the canonical host+database+username+password+properties combo, see H2 Database plugin source code as an example.

Contributing

Refer to our contribution guidelines

LICENSE

Licensed under MIT, see LICENSE

Database (2024)
Top Articles
Nestle Organizational Behavior Project Report
Introducing Project TinyMiniMicro Home Lab Revolution
Everything Candace Owens Gets Wrong in Episode 1 of “A Shot in the Dark”
Hexanaut.io: Trucs et Astuces pour Notre Nouveau Jeu IO
Everyhome For Sale
Haktuts Free Spins Link 2020
Academic calendar 2023 - 2024 - student.uva.nl
Silnafil 25mg Tablet: View Uses, Side Effects, Price and Substitutes | 1mg
What is international trade and explain its types?
Word Hippo Thesaurus
Jug Cousin Crossword Clue
Lucki White House Lyrics
Runic Ward Chest Vault
Lesson 2 Homework 2.5
Who Is Mikaylah? Age, Boyfriend, Net Worth, Wiki & More
truckoo | Gebrauchte LKW mit einem Klick kaufen | Truckoo
Hdmovieshub In
Tooquteforyou Skype
Ky Fl Basketball Game Today
Tyrese Haliburton is not just driving the Indiana Pacers’ system. He is the system
Alex Bodger Stab Video
Culver's Flavor Of The Day Paducah Ky
Brimstone Sands Lost Easels
Does Nick Wheeler Still Talk To His Sister
What To Expect When Moving With a U-Haul Trailer (2024)
Final Schedule Cmu
Teksystems Time And Expense
Jesus Calling June 21St
Bobs Kart Forum
Newsday Crossword Puzzle Brains Only
Bandit Ui
Crytek director says Hunt: Showdown's big August update represents 'a significant relaunch of Hunt: Showdown at a whole new level'
Canterbury Tales (ed. Skeat)/Knight - Wikisource, the free online library
The Nail Lab Buckhead Reviews
Ahrefs Kod Rabatowy
Lady Wicked Playground
12 Incredible Things to Do in Mendocino, California
Covers Ncaab Forum
2013 Chevy Cruze Cooling System Diagram
Eversource Outage Map Cape Cod
Ups Location Near Me Drop Off
My Gluten Free Vegetable Spring Rolls Recipe (low FODMAP, dairy free)
Topeka Pets Craigslist
Amari Cooper Pfr
Integer Division Matlab
Dr. Rolando Lozano Md Elizabeth Nj
2011 Jeep Liberty Serpentine Belt Diagram
24 Hour Lock Up Knoxville Tn
Fireboy And Watergirl Advanced Method
Cheyenne Craigslist
Bourbon Moth Magnolia
Craigslist Metal Roofing
Latest Posts
Article information

Author: Terrell Hackett

Last Updated:

Views: 5972

Rating: 4.1 / 5 (72 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Terrell Hackett

Birthday: 1992-03-17

Address: Suite 453 459 Gibson Squares, East Adriane, AK 71925-5692

Phone: +21811810803470

Job: Chief Representative

Hobby: Board games, Rock climbing, Ghost hunting, Origami, Kabaddi, Mushroom hunting, Gaming

Introduction: My name is Terrell Hackett, I am a gleaming, brainy, courageous, helpful, healthy, cooperative, graceful person who loves writing and wants to share my knowledge and understanding with you.