-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
61 lines (53 loc) · 2.15 KB
/
Jenkinsfile
File metadata and controls
61 lines (53 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
pipeline {
agent any
environment {
OPENSHIFT_PROJECT = 'ritlab' // Change to your OpenShift namespace
APP_NAME = 'tts-app' // Change to your app name
REGISTRY = 'image-registry.openshift-image-registry.svc:5000'
GIT_REPO = 'https://github.com/RitLab/tts-webapp' // Change to your GitHub repo
GIT_BRANCH = 'master'
SERVER = 'https://api.crc.testing:6443'
}
stages {
stage('Checkout Code') {
steps {
git branch: "${GIT_BRANCH}", url: "${GIT_REPO}"
}
}
stage('Build & Push Image') {
steps {
script {
withCredentials([string(credentialsId: "openshift-token", variable: 'OPENSHIFT_TOKEN')]) {
// Log in to OpenShift
sh "oc login --token=$OPENSHIFT_TOKEN --server=${SERVER} --insecure-skip-tls-verify"
// Switch to the project
sh "oc project ${OPENSHIFT_PROJECT}"
// Build image using OpenShift's BuildConfig
sh """
set -e
oc start-build ${APP_NAME} --from-dir=. --follow || exit 1
"""
// Tag and push the image to OpenShift registry
sh """
oc tag ${OPENSHIFT_PROJECT}/${APP_NAME}:dev ${OPENSHIFT_PROJECT}/${APP_NAME}:dev
"""
}
}
}
}
stage('Cleanup Old Images') {
steps {
script {
withCredentials([string(credentialsId: "openshift-token", variable: 'OPENSHIFT_TOKEN')]) {
// Log in to OpenShift
sh "oc login --token=$OPENSHIFT_TOKEN --server=${SERVER} --insecure-skip-tls-verify"
// Prune unused images
sh """
oc adm prune images --confirm --keep-tag-revisions=2
"""
}
}
}
}
}
}