-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
89 lines (80 loc) · 3.02 KB
/
Jenkinsfile
File metadata and controls
89 lines (80 loc) · 3.02 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
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
pipeline {
tools {
maven 'Maven3'
}
agent any
environment {
AKS_REGION='centralus'
ACR_NAME = 'testacr7'
DOCKER_IMAGE_NAME = 'testsbimage'
AKS_RESOURCE_GROUP='test_deploy'
AKS_CLUSTER='testk8s'
AKS_CLUSTER_NAMESPACE='helm-deployment'
HELM_CHART_NAME='mychart'
}
stages {
stage('Azure login') {
steps {
withCredentials([azureServicePrincipal('aksdeployServicePrincipal')]) {
script {
// Azure login
sh 'az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET -t $AZURE_TENANT_ID'
// Login to azure ACR
sh 'az acr login --name ${ACR_NAME}'
// K8S cluster credentials
sh 'az aks get-credentials --resource-group ${AKS_RESOURCE_GROUP} --name ${AKS_CLUSTER} --overwrite-existing'
}
}
}
}
stage('Maven build') {
steps {
// Build springboot app jar
sh 'mvn clean install'
}
}
stage('SpringbootApp: docker push to ACR') {
steps {
// Build Docker image
sh 'docker build -t ${DOCKER_IMAGE_NAME} .'
// Tag Docker image name
sh 'docker tag ${DOCKER_IMAGE_NAME} ${ACR_NAME}.azurecr.io/${DOCKER_IMAGE_NAME}:latest'
// Push Docker image to Azure Container Registry
sh 'docker push ${ACR_NAME}.azurecr.io/${DOCKER_IMAGE_NAME}:latest'
}
}
stage ('SpringbootApp helm deploy') {
steps {
script {
sh "kubectl create namespace ${AKS_CLUSTER_NAMESPACE}"
sh "helm upgrade first --install ${HELM_CHART_NAME} --namespace ${AKS_CLUSTER_NAMESPACE}" //--set image.tag=$BUILD_NUMBER"
}
}
}
// stage('kubectl deploy') {
// steps {
// sh 'az aks get-credentials --resource-group ${AKS_RESOURCE_GROUP} --name ${AKS_CLUSTER} --overwrite-existing'
// sh 'kubectl create namespace ${AKS_CLUSTER_NAMESPACE}'
// sh 'kubectl apply -f aks-store-quickstart.yaml'
// }
// }
}
post {
always {
// Clean up Docker images, containers and workspace.
script {
sh 'docker rmi -f $(docker images -q)'
sh 'docker system prune -f'
deleteDir()
sh 'rm -rf /var/lib/jenkins/.kube/'
sh 'az logout'
}
}
success {
echo 'This runs only if the pipeline is successful'
}
failure {
echo 'This runs only if the pipeline fails'
}
}
}