Jenkins Setup

The following information is for a standard Jenkins setup for running Continuous Integration (CI)/Continuous Delivery (CD) for HERE platform.

Tools

The following tools are used in the CI/CD implementation. The source code for the example application and configuration in the Maven POM files can be viewed in the platform-examples-<release>.zip in the HERE Artifactory, https://repo.platform.here.com/artifactory.

  • Maven
  • JUnit
  • Jenkins
  • Git
  • Gerrit

Maven Plugins

The following Maven plugins are used for the CI server build.

Maven Plugin Description
sonar-maven-plugin SonarQube™ is an open source platform for Continuous Inspection of code quality. The Maven Plugin triggers the code analyzers.
jacoco-maven-plugin The JaCoCo Maven plug-in provides the JaCoCo runtime agent for your tests and allows basic report creation.
maven-surefire-plugin The Surefire Plugin is used during the test phase of the build lifecycle to execute the unit tests of an application.
maven-failsafe-plugin The Failsafe Plugin is designed to run integration tests while the Surefire Plugin is designed to run unit tests.

Jenkins Plugins

The following Maven plugins are used for the CD server.

Note

The Pipeline plugin installs several dependent plugins.

Jenkins Plugin Reference URL
Pipeline Plugin https://wiki.jenkins.io/display/JENKINS/Pipeline+Plugin
Managed Script Plugin https://wiki.jenkins.io/display/JENKINS/Managed+Script+Plugin
Git Plugin https://wiki.jenkins.io/display/JENKINS/Git+Plugin
Job DSL Plugin https://wiki.jenkins.io/display/JENKINS/Job+DSL+Plugin
Build Failure Analyzer https://wiki.jenkins.io/display/JENKINS/Build+Failure+Analyzer
Gerrit Trigger https://wiki.jenkins.io/display/JENKINS/Gerrit+Trigger
Config File Provider Plugin https://wiki.jenkins.io/display/JENKINS/Config+File+Provider+Plugin
Credentials Plugin https://wiki.jenkins.io/display/JENKINS/Credentials+Plugin
Timestamper https://wiki.jenkins.io/display/JENKINS/Timestamper
Build-timeout Plugin https://wiki.jenkins.io/display/JENKINS/Build-timeout+Plugin

Adding HERE Artifactory Access Credentials in Jenkins

When you initially set up your HERE platform credentials, you download and copy a Maven settings.xml file to your $HOME/.m2 directory.

The example below illustrates a sample settings file.

<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
  <server>
    <id>HERE_PLATFORM_REPO</id>
    <username>HERE-a1a2a3a4a5a6a-7777-89aa-1a82-68880b58371c</username>
    <password>XXX</password>
  </server>
</servers>

<profiles>
  <profile>
    <id>default</id>
    <repositories>
      <repository>
        <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>HERE_PLATFORM_REPO</id>
      <name>HERE platform Repository</name>
      <url>https://repo.platform.here.com/artifactory/open-location-platform/</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>HERE_PLATFORM_REPO</id>
      <name>HERE platform Repository</name>
      <url>https://repo.platform.here.com/artifactory/open-location-platform/</url>
      </pluginRepository>
    </pluginRepositories>
  </profile>
</profiles>

<activeProfiles>
  <activeProfile>default</activeProfile>
</activeProfiles>
</settings>

Add Maven User Credentials

To add your user credentials to Maven, follow the steps below.

  1. From the main Jenkins dashboard, select Manage Jenkins.
  2. Select Credentials from the left-hand side menu to display the System sub-menu.
  3. Select the System sub-menu.
  4. Select Global credentials > Add Credentials.
Add Credentials
Figure 1. Add Credentials

Import the Maven settings.xml file

To import your Maven settings file, follow the steps below.

  1. From the main Jenkins dashboard, select Manage Jenkins.
  2. Select the Managed files plugin. This opens the Config File Management dashboard.
  3. Select Add a new Config.
  4. Select Maven settings.xml and click Submit.
  5. Select Server Credentials Add.
  6. Enter HERE_PLATFORM_REPO for ServerId. This matches the <server><id> section from your settings.xml file.
  7. Enter the username and password pair from the downloaded settings.xml file in the Credentials field.
  8. Remove the username and password pair from the downloaded settings.xml file and copy the resulting file into the Content field.
Import Maven Settings
Figure 2. Import Maven Settings

Add OLP CLI Access Credentials in Jenkins

The sharing groups created for each environment must be added to Jenkins in order to gain permission to run OLP CLI commands.

Perform the following steps for each sharing group.

  1. From the main Jenkins dashboard, select Manage Jenkins.
  2. Select Credentials from the left-hand side menu. A System sub-menu opens under Credentials.
  3. Select the System sub-menu.
  4. Select Global credentials > Add Credentials.
  5. Set the input parameters as indicated in the table below.
Label Value
Kind Secret file
Scope Global
File ~/.here/credentials.properties
ID

Add Proxy Access Credentials in Jenkins (optional)

To add proxy access credentials, follow the steps below.

  1. From the main Jenkins dashboard, select Manage Jenkins.
  2. Select Credentials from the left-hand side menu. A System sub-menu opens under Credentials.
  3. Select the System sub-menu.
  4. Select Global credentials > Add Credentials.
  5. Set the input parameters as indicated in the table below.
Label Value
Kind Username with password
Scope Global
Username <proxy username>
Password <proxy password>
ID proxy

Bind Proxy Credentials

To bind the proxy credentials, define the following pipeline DSL, which accesses the 'proxy' credentials created above and assigns "Username" to "USERNAME" and "Password" to "PASSWORD".

withCredentials([usernamePassword(credentialsId: 'proxy', passwordVariable: 'PROXY_PASSWORD', usernameVariable: 'PROXY_USER')]) {
    withEnv(“HTTPS_PROXY=$PROXY_USER:$PROXY_PASSWORD@<proxy address>"){
        ...
    }
}

Add Jenkins DSL Shared Libraries

DSL Shared Libraries should be defined in a separate source control repository and configured in your Jenkins settings. The OLP CLI Helper Groovy class is part of HERE platform Shared Libraries.

Directory Structure

(root)
+- src                     # Groovy source files
|   +- org
|       +- foo
|           +- Bar.groovy  # for org.foo.Bar class
+- vars
|   +- foo.groovy          # for global 'foo' variable
|   +- foo.txt             # help for 'foo' variable
+- resources               # resource files (external libraries only)
|   +- org
|       +- foo
|           +- bar.json    # static helper data for org.foo.Bar

Configure Jenkins to Define Global Shared Libraries

  1. From the main Jenkins dashboard, select Manage Jenkins.
  2. Select Configure System.
  3. Select Global Pipeline Libraries > Add.

Set up Jenkins to Run the Job Based on Jenkinsfile

  1. Create a new Jenkins job.

    New item
    Figure 3. New item
  2. Enter an arbitrary unique job name and select Pipeline. Pipeline
  3. Inside the job configuration Pipeline area, select Pipeline script from SCM.
  4. In SCM, configure your repository type, repository URL, credentials, and other values.
  5. In the Script Path field, enter the relative location to your Jenkinsfile in your project repo. SCM
  6. If you want to trigger the build on Gerrit events, you need to set up Build Triggers » Gerrit events.

For additional information, refer to the following links.

  1. https://platform.here.com
  2. https://www.martinfowler.com/articles/continuousIntegration.html
  3. https://www.thoughtworks.com/continuous-delivery
  4. https://jenkins.io/doc/book/pipeline/shared-libraries/

results matching ""

    No results matching ""