-
Notifications
You must be signed in to change notification settings - Fork 35
/
Jenkinsfile
78 lines (66 loc) · 2.44 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
pipeline {
agent any
environment {
ACR_LOGINSERVER = credentials('ACR_LOGINSERVER')
ACR_ID = credentials('ACR_ID')
ACR_PASSWORD = credentials('ACR_PASSWORD')
}
stages {
stage ('azure-voting-app-redis - Checkout') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/ViniciusSouza/azure-voting-app-redis']]])
}
}
stage ('Build, Lint, & Unit Test') {
steps{
//exectute build, linter, and test runner here
sh '''
echo "exectute build, linter, and test runner here"
'''
}
}
stage ('Docker Build and Push to ACR'){
steps{
sh '''
#Azure Container Registry config
REPO_NAME="azure-voting-app-redis"
ACR_LOGINSERVER="myrepo.azurecr.io"
ACR_ID="myACRid"
ACR_PASSWORD="myACRpassword"
IMAGE_NAME="$ACR_LOGINSERVER/$REPO_NAME:jenkins${BUILD_NUMBER}"
#Docker build and push to Azure Container Registry
cd ./azure-vote
docker build -t $IMAGE_NAME .
cd ..
docker login $ACR_LOGINSERVER -u $ACR_ID -p $ACR_PASSWORD
docker push $IMAGE_NAME
'''
}
}
stage ('Helm Deploy to K8s'){
steps{
sh '''
#Docker Repo Config
REPO_NAME="azure-voting-app-redis"
ACR_LOGINSERVER="myrepo.azurecr.io"
#HELM config
NAME="azure-voting-app-redis"
HELM_CHART="./helm/azure-voting-app-redis"
#Kubenetes config (for safety, in order to make sure it runs in the selected K8s context)
KUBE_CONTEXT="jenkins-k8s-azure"
kubectl config --kubeconfig=/var/lib/jenkins/.kube/config view
kubectl config set-context $KUBE_CONTEXT
#Helm Deployment
helm --kube-context $KUBE_CONTEXT upgrade --install --force $NAME $HELM_CHART --set image.repository=$ACR_LOGINSERVER/$REPO_NAME --set image.tag=jenkins${BUILD_NUMBER}
#If credentials are required for pulling docker image, supply the credentials to AKS by running the following:
#kubectl create secret -n $NAME docker-registry regcred --docker-server=$ACR_LOGINSERVER --docker-username=$ACR_ID --docker-password=$ACR_PASSWORD [email protected]
'''
}
}
}
post {
always {
echo 'Build Steps Completed'
}
}
}