64. Utility Templates

64.1. Initialize Instance Template for Production Line

64.1.1. Introduction

Production Line Templates allows you to create/configure certain task. In order to work properly, Production Line Templates needs some previous configurations. You can do it manually or executing the Initialize Instance Template.

64.1.2. Prerequisites

In order to be able to start this template, you need:

Production Line provides by default the Shared Lib and the plugins, so no actions are required. The only thing that you need to do manually is the creation of the service account.

In order to create the service account you need:

  1. Open the LAM

  2. Press the New User button

    create account
  3. Enter the required parameters

    create account2
  4. Change to Unix tab and enter the required parameters

    create account3

    The user name will be used later in order to login. As this user will do some configuration changes, its primary group must be admins.

  5. Set a password for the user.

    create account4
  6. Press the Save button

    create account5

64.1.3. Template

In order to execute this template, you need to add it into Jenkins manually. In order to do that, you can follow this guide

Parameters

The required parameters are:

  • svcaccount: The service account created as prerequisite. It must be added as a Jenkins credential.

  • installDeploymentPlugins: With this parameter you can install extra plugins into Jenkins. Also, you can add extra template utils.

Execution
  1. Press the Build with Parameters button

  2. Insert the parameters.

  3. If the service account is not added as credential, please add a new entry.

  4. Press the Build button.

  5. Wait until the pipeline ends.

Warning
if any plugin is installed, Jenkins will be restarted and the pipeline will fail. You need to execute it again with the same parameters.
initialize instance
initialize instance2
The result
  • Install plugins stage

    In this stage the following plugins will be installed:

  • Configure SonarQube stage

    This stage is the responsible of configure the Jenkins-SonarQube integration. It will:

    • Generate a SonarQube API token for the user Admin

    • Register the token in Jenkins as credential with the id sonar-token

    • Add the SonarQube server in Jenkins → Manage Jenkins → Configure System → SonarQube servers. The values used are:

      • Name: SonarQube

      • Server URL: http://sonarqube-core:9000/sonarqube (default Production Line SonarQube URL)

      • Server authentication token: sonar-token (generated in the previous step)

    • Add a webhook in SonarQube:

    • Install the following SonarQube plugins:

      • java

      • javascript

      • typescript

      • csharp

      • web

      • cssfamily

      • jacoco

      • checkstyle

      • cobertura

      • smells

      • findbugs

      • scmgit

      • ansible

      • sonar-dependency-check-plugin

    • Restart the SonarQube server in order to enable the plugins installed.

  • Create UTIL templates stage

    Some templates needs that Jenkins has installed some plugins. If the plugins are not installed, the template will fail. In order to prevent this behaviour, we use the initialize-instance to install all plugins required in order templates. Then, we create another templates that will use the plugins installed by initialize-instance. In this stage we create some template utils to configure Jenkins after all required plugins are installed. Those templates are:

  • Configure Nexus 3 stage

    This stage will configure the Production Line Nexus3

    • Enable anonymous access

    • Add a internal user to download/upload docker images

      • username: nexus-api

      • password: The same as the service account created in LAM

    • Create the maven repositories: maven-central, maven-snapshots, maven-release, maven-plugin

    • Create the docker repository

    • Create the npmjs repositories: npmjs, npm-registry, npm

    • Create in Jenkins a new credential with the id nexus-api with the username and password created in nexus3

  • Configure Maven File stage

    This stage adds the nexus3 credentials creadted in the previous stage to the maven global configuration file with the id pl-nexus

    maven config

Now, you are able to execute other templates adding them manually or using the Production Line Market Place.

64.2. Install SonarQube Plugin

64.2.1. Introduction

SonarQube can extends its behaviour by adding plugins. Some on them can be installed by using the SonarQube Marketplace, others can be installed by copying the .jar into the SonarQube plugins folder.

Overview

This template will help you to install SonarQube plugins by copying the .jar into the SonarQube plugins folder. As you do not have access to the Production Line volumes, it will help you when you want to install a plugin that is not installed in the SonarQube Marketplace.

It will:

  • Download the .jar file from a provided URL.

  • Copy the .jar file to the plugins folder.

  • Restart the SonarQube server in order to enable the plugin.

Note
this template only works in a Production Line instance.

64.2.2. Template

This template will be automatically created in your jenkins after executing the Initialize_Instance template inside the UTILS folder with the name Install_SonarQube_Plugin.

For manual creation see: How to add a Template

Important
This template needs the devonfw Production Line Shared Lib
Parameters

The only parameter required is the plugin download URL.

Execution
  1. Press the Build with Parameters button

  2. Insert plugin the download url. Example: https://github.com/dependency-check/dependency-check-sonar-plugin/releases/download/1.2.6/sonar-dependency-check-plugin-1.2.6.jar

  3. Press the Build button.

  4. Wait until the pipeline ends.

build install sonar plugin
build install sonar plugin2

After the execution, when the SonarQube is restarted, you can check that your plugin is installed visiting the Marketplace.

sonar plugin

64.3. Docker Configuration

64.3.1. Introduction

Docker is the most popular container technology. It allows you to build your application in an image and then deploy it into a container.

Overview

This template allow you to configure Jenkins in order to work with docker.

It will:

  • Add docker client as custom tool.

  • Configure docker to work with an external docker dameon.

64.3.2. Prerequisites

In order to execute this template, you need the following plugins installed in your Jenkins:

Important
The initialize instance template will install all plugins if you select 'Docker' or 'Docker+Openshift' in the installDeploymentPlugins parameter

64.3.3. Template

This template will be automatically created in your jenkins after executing the Initialize_Instance template inside the UTILS folder with the name Docker_Configuration.

For manual creation see: How to add a Template

Important
This template needs the devonfw Production Line Shared Lib
Parameters

The only parameter required is remote docker daemon URL. Example: tcp://127.0.0.1:2367

Important
You need to expose the docker daemon manually in your machine. Here you can find how to do it
Warning
This configuration requires that the docker daemon has no security. It’s prepared for development environments, for production environments please add security to your docker daemon.
Execution
  1. Press the Build with Parameters button

  2. Insert remote docker daemon URL.

  3. Press the Build button.

  4. Wait until the pipeline ends.

docker configuration
docker configuration2

Then, you can see that the docker is configured and the remote docker daemon environment variable is set:

docker env var
docker custom tool

The environment variable is setted globally, if you want to use another remote docker daemon for a specific build, you can override the DOCKER_HOST environment variable in your job.

If the DOCKER_HOST is already setted globally, when you execute again this template the value will not be changed. You need to change the value manually at: Jenkins → Manage Jenkins → Configure System → Global properties

64.4. Docker Configuration

64.4.1. Introduction

OpenShift is a docker container orchestrator built on top Kubernetes.

Overview

This template allow you to configure Jenkins in order to work with OpenShift.

It will:

  • Add OpenShift client as custom tool.

  • Configure an OpenShift cluster to work with.

64.4.2. Prerequisites

In order to execute this template, you need the following plugins installed in your Jenkins:

Note
The initialize instance template will install all plugins if you select Openshift or Docker+Openshift in the installDeploymentPlugins parameter

64.4.3. Template

This template will be automatically created in your jenkins after executing the Initialize_Instance template inside the UTILS folder with the name Openshift_Configuration.

For manual creation see: How to add a Template

Important
This template needs the devonfw Production Line Shared Lib
Parameters

The required parameters are:

  • ocName: The name of the OpenShift connection. You can define multiple OpenShift connections by changing the name.

  • ocUrl: The OpenShift URL.

  • ocProject: The OpenShift Project.

  • ocToken: The OpenShift token. In order to have a long-term token, this token should be a service account token.

Execution
  1. Press the Build with Parameters button

  2. Insert the parameters.

  3. If the OpenShift token is not added as credential, please add a new entry.

  4. Press the Build button.

  5. Wait until the pipeline ends.

Warning
If a cluster already exists with the provided name, it will not modify anything.
openshift configuration
openshift configuration2
openshift configuration3

You can add more clusters by executing the template again or in Jenkins → Manage Jenkins → Configure System

openshift clusters
Last updated 2021-03-17 08:55:56 UTC