Software and Systems How-To's, Tutorials, Demos, Notes

Using Jenkins Pipeline

Register to Gogs

First we need to register to Gogs as a developer. For uniformity, we use the following convention:

Important: Use the correct value of userX

username: userX email: userX@example.com password: userX

Register To Gogs

Create a new Repository

Click the + sign of My Repositories. Set the following details:

Click Create Repository

Repository Details

Copy the new repository url to the clipboard

Repository URL

Import source code to the Repository

Todo After Import

Create a Mongodb database instance using Mongodb template

MongoDB template

MongoDB template values

Create a new application using NodeJs template

Click “Add to Project”, search for NodeJs

New NodeJS Apps

Input the details as shown below. The project should be the project assigned to you.

New NodeJs App Details

Click on “advanced options”. Scroll to Deployment Configuration and add Environment Variable

PORT = 8080

Click on Create.

The build will fail in this case because the repository is private.

Add Gogs credentials to your OpenShift project

Build Error

oc project

Edit Build Config

Advanced Options

Set Source Secret

Todo Build Logs

Todo Deployment

Todo Page

Create the Build Pipeline

apiVersion: v1
kind: BuildConfig
metadata:
  labels:
    app: jenkins-pipeline-example
    name: sample-pipeline
    template: application-template-sample-pipeline
  name: todo-pipeline
spec:
  runPolicy: Serial
  strategy:
    jenkinsPipelineStrategy:
      jenkinsfile: |-
        node('nodejs') {
          stage('build') {
            openshiftBuild(buildConfig: 'todo', showBuildLogs: 'true')
          }
          stage('deploy') {
            openshiftDeploy(deploymentConfig: 'todo')
          }
 
          //stage( 'Wait for approval')
          //input( 'Aprove to production?')
          //stage('Deploy UAT'){
            //openshiftDeploy(deploymentConfig: 'todo', namespace: 'todo-uat')
          //}

        }
    type: JenkinsPipeline
  triggers:
  - github:
      secret: secret101
    type: GitHub
  - generic:
      secret: secret101
    type: Generic
oc create -f todo_pipeline.yml

Todo Build Pipeline

Next Exercise: Configure the CI/CD pipeline