openshift/templates/builds/pipeline-bc.yaml
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
creationTimestamp: '2020-11-05T19:12:39Z'
labels:
application: jag-document-utils-api
template: jag-document-utils-api-pipeline-template
name: jag-document-utils-api-pipeline
namespace: ag-pssg-is-tools
spec:
failedBuildsHistoryLimit: 5
nodeSelector: {}
output: {}
postCommit: {}
resources: {}
runPolicy: Serial
source:
contextDir: src/backend
git:
ref: master
uri: 'https://github.com/bcgov/jag-document-utils'
type: Git
strategy:
jenkinsPipelineStrategy:
env:
- name: APP_NAME
value: jag-document-utils-api
- name: LIFECYCLE_WEBHOOK
- name: GIT_SOURCE_URL
value: 'https://github.com/bcgov/jag-document-utils'
- name: GIT_SOURCE_REF
value: master
- name: GIT_CREDENTIALS_ID
value: cjpybwYjEBI8vN2lYGAhYmywnpjFqANRRJarS5yf
- name: GIT_CONTEXT_DIR
value: src/backend
- name: CHECKOUT_SRC
value: '${gitCheckoutRequired}'
- name: JENKINS_POD
value: maven
- name: TOOLS_NAMESPACE
value: ag-pssg-is-tools
- name: DEV_NAMESPACE
value: ag-pssg-isdev
- name: TEST_NAMESPACE
value: ag-pssg-is-test
- name: PROD_NAMESPACE
value: ag-pssg-is-prod
- name: ROUTE_TYPE
value: private
jenkinsfile: |
try {
node("${JENKINS_POD}") {
// Build Image
stage("Build ${APP_NAME}") {
openshift.withCluster() {
openshift.withProject() {
sh 'oc start-build ${APP_NAME} -n ${TOOLS_NAMESPACE} --wait'
}
}
}
// Tag Image for Dev
stage('Promote to DEV') {
openshift.withCluster() {
openshift.withProject(){
sh "echo Tagging image for DEV"
sh 'oc tag ${APP_NAME}:latest ${APP_NAME}:dev'
}
}
}
stage("Deploy to DEV") {
openshift.withCluster() {
openshift.withProject() {
sh 'echo Wait for Demo app to rollout completely.'
sh 'oc rollout status -n ${DEV_NAMESPACE} dc/${APP_NAME} --watch'
}
}
}
// Tag Image for Test
stage('Promote to TEST') {
timeout(time: 10, unit: 'MINUTES') {
script {
input message: 'Promote application to Test?'
}
}
openshift.withCluster() {
openshift.withProject() {
sh "echo Tagging image for TEST"
sh 'oc tag ${APP_NAME}:latest ${APP_NAME}:test'
}
}
}
stage("Deploy to TEST") {
openshift.withCluster() {
openshift.withProject() {
sh 'echo Wait for Demo app to rollout completely.'
sh 'oc rollout status -n ${TEST_NAMESPACE} dc/${APP_NAME} --watch'
}
}
}
// Tag Image for Prod
stage('Promote to PROD') {
timeout(time: 10, unit: 'MINUTES') {
script {
input message: 'Promote application to Prod?'
}
}
openshift.withCluster() {
openshift.withProject() {
sh "echo Tagging image for PROD"
sh 'oc tag ${APP_NAME}:latest ${APP_NAME}:prod'
}
}
}
stage("Deploy to PROD") {
openshift.withCluster() {
openshift.withProject() {
sh 'echo Wait for Demo app to rollout completely.'
sh 'oc rollout status -n ${PROD_NAMESPACE} dc/${APP_NAME} --watch'
}
}
}
}
} catch (err) {
echo "in catch block"
currentBuild.result = 'FAILURE'
env.ERR = "${err}"
node {
sh "curl -XPOST '${LIFECYCLE_WEBHOOK}' -H 'Content-type: application/json' --data '{\"username\":\"The Pipe Lion\",\"icon_emoji\":\":lion_face:\",\"text\": \"${APP_NAME} Pipeline Failure - ${ERR}\"}'"
}
echo "Caught: ${err}"
throw err
}
type: JenkinsPipeline
successfulBuildsHistoryLimit: 5
triggers:
- type: ConfigChange
- github:
secret: '${GITHUB_WEBHOOK_SECRET}'
type: GitHub
status:
lastVersion: 0