remkohdev
  • Learn to Code
  • About Me
  • CI/CD
    • DevOps101
      • Welcome
  • OpenShift
    • Setup OpenShift
      • Setup Minishift
    • Builds
      • Source-to-Image (S2I)
        • Setup S2I
        • Build, Run, Deploy from Source
      • Jenkins Pipeline
    • Jenkins as a Service
      • Setup Jenkins on Openshift
      • Create a Pipeline for Java Spring Boot
  • Istio
    • Setup Istio on IKS
      • Login to IKS
    • Setup Istio on Openshift 3.11
    • Traffic Shifts with a VirtualService
    • Telemetry of Metrics using Prometheus
    • Telemetry of Distributed Tracing using Jaeger
    • Security with Mutual TLS (mTLS)
  • Apache Kafka
    • Setup Apache Kafka on IBM Cloud
    • Setup Apache Kafka on OpenShift
    • Produce and Consume Streams with Kafka Console Tools
    • Produce and Consume Streams with Spring Boot
    • Using the Event Streams CLI
    • Kafka Admin API
  • API Connect
    • APIC CLI
      • Manage API Lifecycle with apic
    • Securing your API
      • Setup AppID
      • Setup API Connect
      • Optional: Add Node-RED Test Server
      • Add 3rd Party OAuth OIDC
        • Create a Custom AppID API
        • Add a Security Definition to your API
Powered by GitBook
On this page

Was this helpful?

  1. OpenShift
  2. Builds

Jenkins Pipeline

PreviousBuild, Run, Deploy from SourceNextJenkins as a Service

Last updated 5 years ago

Was this helpful?

Pipeline workflows are defined in a Jenkinsfile, either embedded directly in the build configuration, or supplied in a Git repository. You can use the from the Catalog to run the Pipeline and create a web hook to trigger builds after source code updates.

Add the following to your project,

pipeline {
  agent {
    label 'maven'
  }  
  stages {
    stage('Login') {
      steps {
        withCredentials([usernamePassword(
		  credentialsId: 'openshift-login-api-token', 
		  usernameVariable: 'USERNAME',
		  passwordVariable: 'OC_API_TOKEN',
		)]) {
	        sh "oc login ${OC_URL}:${OC_PORT} --token=${OC_API_TOKEN}"
		}
      }
    }
    stage('Delete Project') {
      steps {
          sh 'oc delete project springclient-ns'
      }
    }
    stage('Maven Build') {
      steps {
		echo 'Build jar file'
		sh 'mvn clean install -DskipTests=true'
      }
    }
    stage('Run Unit Tests') {
      steps {
        echo 'Run unit tests'
		sh 'mvn test'
      }
    }
    stage('Create Project') {
      steps {
		echo 'Create Project'
		script {
		    sh 'oc new-project springclient-ns'
		    sh 'oc project springclient-ns'
	  	}
      }
    }
    stage('Deploy') {
      steps {
        echo 'Deploy application'
		script {
		    sh 'oc new-app --name springclient \'registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:1.6~https://github.com/remkohdev/spring-client\' --strategy=source --allow-missing-images --build-env=\'JAVA_APP_JAR=hello.jar\''
        }
      }
    }
    stage('Expose') {
      steps {
		echo 'Expose Route'
		script {
		    sh 'oc expose svc/springclient'
        }
      }
    }
  }
}

The Jenkins service on OpenShift has built-in support.

Jenkins as a Service
Jenkins Pipeline
oc cli