forked from LoksaiETA/devops-java-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
76 lines (68 loc) · 2.54 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
pipeline {
agent { label 'awsdevops' }
tools {
// Install the Maven version configured as "M3" and add it to the path.
jdk "aws_open_jdk"
maven "slave_maven"
}
environment {
DOCKERHUB_CREDENTIALS=credentials('dockerloginid')
}
stages {
stage('SCM Checkout') {
steps {
// Get some code from a GitHub repository
git 'https://github.com/LoksaiETA/devops-java-webapp.git'
}
}
stage('Maven Build') {
steps {
// Run Maven on a Unix agent.
sh "mvn -Dmaven.test.failure.ignore=true clean package"
}
}
stage("Docker build"){
steps {
sh 'docker version'
sh "docker build -t loksaieta/loksai-eta-app:${BUILD_NUMBER} ."
sh 'docker image list'
sh "docker tag loksaieta/loksai-eta-app:${BUILD_NUMBER} loksaieta/loksai-eta-app:latest"
}
}
stage('Login2DockerHub') {
steps {
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
}
}
stage('Approve - push Image to dockerhub'){
steps{
//----------------send an approval prompt-------------
script {
env.APPROVED_DEPLOY = input message: 'User input required Choose "yes" | "Abort"'
}
//-----------------end approval prompt------------
}
}
stage('Push2DockerHub') {
steps {
sh "docker push loksaieta/loksai-eta-app:latest"
}
}
stage('Approve - Deployment to Kubernetes Cluster'){
steps{
//----------------send an approval prompt-----------
script {
env.APPROVED_DEPLOY = input message: 'User input required Choose "yes" | "Abort"'
}
//-----------------end approval prompt------------
}
}
stage('Deploy to Kubernetes Cluster') {
steps {
script {
sshPublisher(publishers: [sshPublisherDesc(configName: 'kubernetescluster', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'kubectl apply -f k8smvndeployment.yaml', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '.', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '*.yaml')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
}
}
}