forked from UtsavDesai26/CICD-Pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
124 lines (114 loc) · 4.12 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env groovy
pipeline {
agent any
environment {
NEW_VERSION = '1.3'
}
parameters {
choice(name: 'VERSION', choices:['1','2', '3'], description: '')
booleanParam(name: 'executeTest', defaultValue : true, description: '')
}
tools{
maven 'maven-3.9.0'
}
stages {
// stage('Checkout') {
// steps {
// git branch: 'master', credentialsId: 'git-credentials', url: 'https://github.com/learnwithparth/springboot-jenkins.git'
// }
// }
stage('init'){
steps{
script{
gv = load "script.groovy"
//sh "git clone https://github.com/learnwithparth/springboot-jenkins.git"
}
}
}
stage('config'){
steps{
script{
gv.config()
}
}
}
stage('build') {
steps {
script{
echo 'building the application'
echo "Software version is ${NEW_VERSION}"
sh 'mvn build-helper:parse-version versions:set -DnewVersion=\\\${parsedVersion.majorVersion}.\\\${parsedVersion.nextMinorVersion}.\\\${parsedVersion.incrementalVersion}\\\${parsedVersion.qualifier?}'
sh 'mvn clean package'
def version = (readFile('pom.xml') =~ '<version>(.+)</version>')[0][2]
env.IMAGE_NAME = "$version-$BUILD_NUMBER"
sh "docker build -t utsavdesai26/spring-boot:${IMAGE_NAME} ."
}
}
}
stage('test') {
when{
expression{
params.executeTest
}
}
steps {
script{echo 'testing the application...'
sh 'mvn test'}
}
}
stage('deploy') {
// sshagent(['Production']) {
// // some block
// }
input{
message "Select the environment to deploy"
ok "done"
parameters{
choice(name: 'Type', choices:['Dev','Test','Deploy'], description: '')
}
}
steps {
script{echo 'deploying the application...'
withCredentials([usernamePassword(credentialsId: 'docker', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]){
sh "echo ${PASSWORD} | docker login -u ${USERNAME} --password-stdin"
sh "docker push utsavdesai26/spring-boot:${IMAGE_NAME}"
}}
}
}
// stage('commit and push'){
// steps{
// script{
// withCredentials([usernamePassword(credentialsId: 'git-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]){
// //def encodedPassword = URLEncoder.encode("$PASSWORD",'UTF-8')
// sh 'git config --global user.email "learnwithparth.in@gmail.com"'
// sh 'git config --global user.name "learnwithparth"'
//
// sh 'git status'
// sh 'git branch'
// sh 'git config --list'
//
// //sh "git remote set-url origin https://${USERNAME}:${PASSWORD}@github.com/learnwithparth/springboot-jenkins.git"
//
// sh 'git add .'
// sh 'git status'
// sh 'git commit -m "version change updated"'
// //sh 'git push origin HEAD:master'
// sh "git push -u origin master"
// //sh "git push https://${USERNAME}:${PASSWORD}@github.com/learnwithparth/springboot-jenkins.git"
// }
// }
// }
// }
}
post{
always{
echo 'Executing always....'
}
success{
echo 'Executing success'
}
failure{
echo 'Executing failure'
}
}
}