forked from Yan316/example-product-service
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile-azure
77 lines (70 loc) · 2.55 KB
/
Jenkinsfile-azure
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
pipeline {
agent any
environment {
ACR_CREDS = credentials('acr-credentials')
DOCKER_REGISTRY = 'mydevopsacr001.azurecr.io'
PROJECT_NAME = 'example-product-service'
K8S_NAMESPACE = 'development'
DOCKER_IMAGE = "${DOCKER_REGISTRY}/${PROJECT_NAME}:${env.BUILD_TIMESTAMP}.${env.BUILD_ID}"
DOCKER_LATEST_IMAGE = "${DOCKER_REGISTRY}/${PROJECT_NAME}:latest"
JIB_IMAGE = "net.thoughtworks/${PROJECT_NAME}:latest"
}
stages {
stage('clone repository') {
steps {
sh 'echo "Cloning GitHub repository ..."'
checkout scm
}
}
// stage('Create Docker Environment') {
// steps {
// sh """
// docker-compose -f src/test/resources/docker-compose.yml down
// docker-compose -f src/test/resources/docker-compose.yml up -d
// sleep 10
// """
// }
// }
stage('build Project') {
steps {
sh """
sudo ./gradlew clean build -Dorg.gradle.daemon=false
"""
}
}
// stage('Destroy Docker Environment') {
// steps {
// sh """
// docker-compose -f src/test/resources/docker-compose.yml down
// """
// }
// }
stage('push image to ACR') {
steps {
sh """
./gradlew jibDockerBuild
docker tag ${JIB_IMAGE} ${DOCKER_IMAGE}
docker tag ${JIB_IMAGE} ${DOCKER_LATEST_IMAGE}
docker login ${DOCKER_REGISTRY} -u ${ACR_CREDS_USR} -p ${ACR_CREDS_PSW}
docker push ${DOCKER_IMAGE}
docker push ${DOCKER_LATEST_IMAGE}
"""
}
}
stage('deploy to dev use AKS') {
steps {
sh 'echo "Using Kubectl to deploy application on AKS"'
withKubeConfig(
caCertificate: '',
contextName: '',
credentialsId: 'aks-credentials',
serverUrl: 'https://akslab-8b97af61.hcp.eastasia.azmk8s.io:443') {
sh """
sed \'s#{{ docker_image }}#${DOCKER_IMAGE}#g\' aks-shells/app-update-deploy.tpl.yaml > aks-shells/update-deploy.yaml
kubectl apply -f aks-shells/update-deploy.yaml -n ${K8S_NAMESPACE}
"""
}
}
}
}
}