arnaud-deprez / demo-jenkins-pipeline-gradle

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example of a Jenkins pipeline with gradle

There are a lot of example of Jenkins pipeline on openshift with maven and Nexus 2 but not that much with gradle and Nexus 3. This project aims to be a PoC and serves as guideline for who wants to play with.

Openshift

This example has been tested with Minishift.

To start a new Openshift instance:

minishift config set cpus 4
minishift config set memory 4GB
minishift start

Prerequisite

In this example, we will create one project "cicd". This project will contain all the CICD infrastructure such as:

  • Jenkins master/slave: to orchestrate the pipeline

  • Nexus 3: to store the generated artifacts (in this case, the jars)

  • Sonar: for code analysis

First, let’s import official redhat image:

oc login -u system:admin
oc project openshift
oc create -f https://raw.githubusercontent.com/jboss-openshift/application-templates/master/jboss-image-streams.json

CICD project

Create the "cicd" project:

oc new-project cicd
Jenkins

Create jenkins instance in current project (cicd):

oc new-app jenkins-persistent -p MEMORY_LIMIT=1Gi \
    -p VOLUME_CAPACITY=2Gi

This will also create a "jenkins" service account dedicated the jenkins pods.

Create the jenkins gradle slave with this guide.

Nexus 3

Next, you can install Nexus 3 by following this guide.

Pipeline definition

The project will go to several steps:

  1. Build: jars

  2. Tests

  3. Build docker image: this use java redhat s2i image

  4. Deploy in dev

  5. Deploy in staging

  6. Wait for approval

  7. Deploy in prod

So first, let’s create these projects:

oc new-project dev
oc new-project staging
oc new-project prod

As Jenkins will have to edit these 3 projects, we must give permission to its service account:

oc policy add-role-to-user edit system:serviceaccount:cicd:jenkins -n dev
oc policy add-role-to-user edit system:serviceaccount:cicd:jenkins -n staging
oc policy add-role-to-user edit system:serviceaccount:cicd:jenkins -n prod

Then in cicd project, create the pipeline BuildConfig:

oc create -n cicd -f openshift/demo-pipeline.yml

About


Languages

Language:Java 100.0%