Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleMaven build on a Linux agent
node{
  stage ('Build') {

    git url: 'https://github.com/cyrille-leclerc/multi-module-maven-project'

    withMaven(
        // Maven installation declared in the Jenkins "Global Tool Configuration"
        maven: 'M3maven-3',
        // Maven settings.xml file defined with the Jenkins Config File Provider Plugin
        // We recommend to define Maven settings.xml andglobally globalat settingsthe canfolder alsolevel beusing defined in Jenkins Global Tools Configuration
    
        // navigating to the folder configuration in the section "Pipeline Maven Configuration / Override global Maven configuration"
   mavenSettingsConfig: 'my-maven-settings',    // or globally to  mavenLocalRepo: '.repositorythe entire master navigating to  "Manage Jenkins / Global Tools Configuration"
        mavenSettingsConfig: 'my-maven-settings') {

      // Run the maven build
      sh "mvn clean installverify"

    } // withMaven will discover the generated Maven artifacts, JUnit Surefire & FailSafe & FindBugs & SpotBugs reports...
  }
}

Within a node or a docker.image block, create a withMaven block to setup a with maven environment. The configured environment will be used when calling maven inside the block by using sh mvn or bat mvn. The following parameters can be used to configure maven:

...

  • Create an empty MySQL database with a dedicated MySQL user with permissions for Data Manipulation Language actions (DML) and Data Definition Language (DDL) actions
    • Tested with MySQL 8.0, with MariaDB 10.2 and 10.3 and with Amazon Aurora MySQL 5.6
  • Install the Jenkins "MySQL Database" plugin
    • Navigate to "Manage Jenkins / Manage Plugins / Available", select the "MySQL Database" plugin and click on "Download now and install after restart"
  •  Configure the Pipeline Maven Plugin to use the created MySQL database
    • Create Jenkins credentials for the MySQL connection navigating to "Credentials" on the left menu
    • Navigate to "Manage Jenkins / Global Tools Configuration" and go to the "Pipeline Maven Configuration"
    • Image Modified
    • In the Database configuration section, define the following
      • JDBC URL: url of the database, e.g. "jdbc:mysql://mysql.example.com/jenkins"
      • JDBC Credentials: select the credentials of the MySQL database
      • The parameters recommended by the Hikari Connection Pool team are used by default for the MySQL connections and for the datasource (max pool size:10, server side prepared statements cache with 250 entries...).  To overwrite these defaults, click on the "Advanced Database Convfiguration" button.
    • Click on "Validate Database Configuration" button to verify that the connection is successful
    • Click on "Save"
    • Image Modified


Using a PostgreSQL Database (since 3.7.0)

...

The

...

Feedback welcome!

The Jenkins Pipeline Maven Plugin relies on a database to store its data (list of dependencies and of generated artifacts of each build...).

By default, the Jenkins Pipeline Maven Plugin uses an H2 embedded database but it is recommended to use an external PostgreSQL or MySQL / MariaDB database.

Configuration steps to use a MySQLPostgreSQL:

  • Create an empty PostgreSQL database with a dedicated PostgreSQL user with permissions for Data Manipulation Language actions (DML) and Data Definition Language (DDL) actions
    • Tested with PostgreSQL 10.6 and 11.3
  • Install the Jenkins the "PostgreSQL API" plugin
    • Navigate to "Manage Jenkins / Manage Plugins / Available", select the "PostgreSQL API" plugin and click on "Download now and install after restart"
  •  Configure the Pipeline Maven Plugin to use the created PostgreSQL database
    • Create Jenkins credentials for the PostgreSQL connection navigating to "Credentials" on the left menu
    • Navigate to "Manage Jenkins / Global Tools Configuration" and go to the "Pipeline Maven Configuration"
    • In the Database configuration section, define the following
      • JDBC URL: url of the database, e.g. "jdbc:postgresql://postgresql.example.com:5432/jenkins"
      • JDBC Credentials: select the credentials of the PostgreSQL database
      • The underlying datasource, HikariCP, comes with sensible default configuration values (see here). To overwrite these defaults, click on the "Advanced Database Configuration" button.
    • Click on "Validate Database Configuration" button to verify that the connection is successful
    • Click on "Save"
    • Navigate to "Manage Jenkins / Global Tools Configuration" and go to the "Pipeline Maven Configuration" to verify that the database connection is successful and the database tables have been created (see screenshot above)

FAQ

Anchor
withMavenAndDockerPipeline
withMavenAndDockerPipeline

...