-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathjenkinsfile
63 lines (63 loc) · 2.25 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
pipeline {
agent any
environment {
registry = 'tushardashpute/springboohello:latest'
registryCredentials = 'docker_credentials'
dockerImage = ''
}
stages {
stage ('SCM') {
steps {
checkout([$class: 'GitSCM',
branches: [[name: '*/main']], doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
userRemoteConfigs: [[url: 'https://github.com/tushardashpute/springboohello-CICD.git']]])
}
}
stage ('Build Artifact') {
steps {
sh 'mvn clean install'
}
}
stage ('Build Docker Image') {
steps {
script {
dockerImage = docker.build registry
}
}
}
stage ('Docker Push') {
steps {
script {
docker.withRegistry('',registryCredentials) {
dockerImage.push()
}
}
}
}
stage("Deploy"){
steps{
echo "Current workspace is $WORKSPACE"
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'aws_configure', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
withCredentials([kubeconfigFile(credentialsId: 'kube-credentials', variable: 'KUBECONFIG')]) {
sh '''kubectl apply -f springboot-deployment.yaml
kubectl apply -f springboot-service.yaml
'''
}
}
}
}
stage("Check Pods & Services"){
steps{
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'aws_configure', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
withCredentials([kubeconfigFile(credentialsId: 'kube-credentials', variable: 'KUBECONFIG')]) {
sh '''kubectl get pods
kubectl get svc
'''
}
}
}
}
}
}