forked from gavinfish/mywebapi
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJenkinsfile
More file actions
98 lines (86 loc) · 3.77 KB
/
Jenkinsfile
File metadata and controls
98 lines (86 loc) · 3.77 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
90
91
92
93
94
95
96
97
98
node('master') {
// Variable to record user's input
def userInput
def devSpaceNamespace = "$env.GITHUB_PR_SOURCE_BRANCH-helm"
def releaseName = "mywebapi${devSpaceNamespace}"
stage('init') {
checkout scm
}
stage('build') {
acrQuickTask azureCredentialsId: env.AZURE_CRED_ID,
imageNames: [[image: "$env.ACR_REGISTRY/$env.IMAGE_NAME:$env.BUILD_NUMBER"]],
registryName: env.ACR_NAME,
resourceGroupName: env.ACR_RES_GROUP,
dockerfile: 'Dockerfile.develop'
}
stage('create dev space') {
devSpacesCreate aksName: env.AKS_NAME,
azureCredentialsId: env.AZURE_CRED_ID,
kubeconfigId: env.KUBE_CONFIG_ID,
resourceGroupName: env.AKS_RES_GROUP,
sharedSpaceName: env.PARENT_DEV_SPACE,
spaceName: devSpaceNamespace
}
stage('deploy') {
def registrySecretName = "helm-secret-$env.BUILD_NUMBER"
sh "kubectl create secret docker-registry ${registrySecretName} --docker-server=$env.ACR_REGISTRY --docker-username=$env.ACR_NAME --docker-password=$env.ACR_SECRET --namespace=${devSpaceNamespace}"
sh "helm init --tiller-namespace azds"
sh "helm upgrade ${releaseName} ./charts/mywebapi --install --force --namespace ${devSpaceNamespace} --set image.repository=$env.ACR_REGISTRY/$env.IMAGE_NAME --set image.tag=$env.BUILD_NUMBER --set ingress.hosts={localhost} --set imagePullSecrets[0].name=${registrySecretName} --tiller-namespace azds"
}
stage('smoketest') {
// CI testing against http://$env.azdsprefix.$env.TEST_ENDPOINT"
SLEEP_TIME = 30
SITE_UP = false
for (int i = 0; i < 10; i++) {
sh "sleep ${SLEEP_TIME}"
code = "0"
try {
code = sh returnStdout: true, script: "curl -sL -w '%{http_code}' 'http://$env.azdsprefix.$env.TEST_ENDPOINT/greeting' -o /dev/null"
} catch (Exception e){
// ignore
}
if (code == "200") {
sh "curl http://$env.azdsprefix.$env.TEST_ENDPOINT/greeting"
SITE_UP = true
break
}
}
if(!SITE_UP) {
echo "The site has not been up after five minutes"
}
}
stage('confirm merge') {
// This is just an example for how an email can be triggered… can be anything and up to customers to define.
// mail (to: 'to@example.com',
// subject: "Job ${env.JOB_NAME}' (${env.BUILD_NUMBER}) is waiting for input",
// body: "Please go to ${env.BUILD_URL}.")
// input 'Ready to go?'
// Wait for users to decide whether continue the process
try {
userInput = input(
id: 'Proceed1', message: 'Do you want to apply changes in shared namespace and delete private dev space?', parameters: [
[$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm you want to continue the process']
])
} catch(err) { // input false
echo "Aborted"
}
}
if (userInput == true) {
stage('deploy') {
// Apply the deployment to shared namespace in AKS using acsDeploy, Helm or kubectl
}
stage('Verify') {
// verify the staging environment is working properly
}
stage('cleanup') {
devSpacesCleanup aksName: env.AKS_NAME,
azureCredentialsId: env.AZURE_CRED_ID,
devSpaceName: devSpaceNamespace,
kubeConfigId: env.KUBE_CONFIG_ID,
resourceGroupName: env.AKS_RES_GROUP,
helmReleaseName: releaseName
}
} else {
// Send a notification
}
}