forked from kuldeepsingh99/openshift-jenkins-cicd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
78 lines (76 loc) · 2.32 KB
/
Jenkinsfile
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
pipeline
{
agent {
label 'maven'
}
stages
{
stage('Build App')
{
steps
{
git branch: 'main', url: 'https://github.com/Shirisha1516/openshift-jenkins-cicd.git'
script {
def pom = readMavenPom file: 'pom.xml'
version = pom.version
}
sh "mvn install"
}
}
stage('Create Image Builder') {
when {
expression {
openshift.withCluster() {
openshift.withProject() {
return !openshift.selector("bc", "sample-app-jenkins-new").exists();
}
}
}
}
steps {
script {
openshift.withCluster() {
openshift.withProject() {
openshift.newBuild("--name=sample-app-jenkins-new", "--image-stream=openjdk18-openshift:1.14-3", "--binary=true")
}
}
}
}
}
stage('Build Image') {
steps {
sh "rm -rf ocp && mkdir -p ocp/deployments"
sh "pwd && ls -la target "
sh "cp target/openshiftjenkins-0.0.1-SNAPSHOT.jar ocp/deployments"
script {
openshift.withCluster() {
openshift.withProject() {
openshift.selector("bc", "sample-app-jenkins-new").startBuild("--from-dir=./ocp","--follow", "--wait=true")
}
}
}
}
}
stage('deploy') {
when {
expression {
openshift.withCluster() {
openshift.withProject() {
return !openshift.selector('dc', 'sample-app-jenkins-new').exists()
}
}
}
}
steps {
script {
openshift.withCluster() {
openshift.withProject() {
def app = openshift.newApp("sample-app-jenkins-new", "--as-deployment-config")
app.narrow("svc").expose();
}
}
}
}
}
}
}