-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
82 lines (77 loc) · 3.06 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
pipeline {
environment {
githubUrl = 'https://github.com/Kroshwan/TestWebApp'
githubBranch = 'master'
dockerRegistry = 'https://registry.hub.docker.com'
dockerCredentials = 'docker-credentials'
dockerImage = 'kroshwan/testwebapp'
azureResourceGroup = 'rg_aks_tf'
azureAKSCluster = 'k8s_cluster'
azureServicePrincipalId = 'azureServicePrincipal'
}
agent any
stages {
stage ('Checkout') {
steps {
git url: "${githubUrl}", branch: "${githubBranch}"
}
}
stage ('Restore Packages') {
steps {
sh "dotnet restore"
}
}
stage ('Clean') {
steps {
sh "dotnet clean"
}
}
stage ('Build') {
steps {
sh "dotnet build --configuration Release"
}
}
stage('Build image') {
steps {
script {
docker.withRegistry("${dockerRegistry}", "${dockerCredentials}"){
def app = docker.build("${dockerImage}")
app.push()
}
}
}
}
stage('Deploy Dev'){
steps {
withCredentials([azureServicePrincipal(azureServicePrincipalId)]) {
sh """
az login --service-principal -u "\$AZURE_CLIENT_ID" -p "\$AZURE_CLIENT_SECRET" -t "\$AZURE_TENANT_ID"
kubectl config unset clusters."${azureAKSCluster}"
az aks get-credentials --resource-group "${azureResourceGroup}" --name "${azureAKSCluster}"
kubectl get ns dev || kubectl create ns dev
kubectl --namespace=dev apply -f service.yaml
kubectl --namespace=dev apply -f Deployment-dev.yaml
"""
}
}
}
stage('Deploy Prod'){
steps {
withCredentials([azureServicePrincipal(azureServicePrincipalId)]) {
sh """
az login --service-principal -u "\$AZURE_CLIENT_ID" -p "\$AZURE_CLIENT_SECRET" -t "\$AZURE_TENANT_ID"
kubectl config unset clusters."${azureAKSCluster}"
az aks get-credentials --resource-group "${azureResourceGroup}" --name "${azureAKSCluster}"
kubectl get ns prod || kubectl create ns prod
kubectl --namespace=prod apply -f service.yaml
kubectl --namespace=prod apply -f Deployment-prod.yaml
#kubectl config set-context prod --namespace=prod
#kubectl config use-context prod
#cat Deployment.yaml | sed 's/{{NAMESPACE}}/prod/g' | kubectl apply -f -
#kubectl set image deployments/webapp-deploy container-pod=kroshwan/testwebapp:latest
"""
}
}
}
}
}