Pipeline workflows are defined in a Jenkinsfile, either embedded directly in the build configuration, or supplied in a Git repository. You can use the Jenkins as a Service from the Catalog to run the Pipeline and create a web hook to trigger builds after source code updates.
Copy 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'
}
}
}
}
}