forked from ksv102/jenkine-pipeline-maven-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
90 lines (77 loc) · 3.29 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
83
84
85
86
87
88
89
90
properties([pipelineTriggers([githubPush()])])
pipeline {
agent any
environment {
registryUrl = "hidpdeveastusbotacr.azurecr.io"
}
stages {
stage( 'Unit_test') {
steps {
sh 'mvn test'
}
}
stage( 'Build') {
steps {
script {
datas = readYaml (file : "$WORKSPACE/config.yml")
echo "build type is: ${datas.Build_type}"
if( "${datas.Build_type}" == "maven" )
{
sh 'mvn clean install -DskipTests=True'
}
else( "${datas.Build_type}" == "gradle" )
{
sh 'gradle build'
}
}
}
}
stage('SonarQube analysis') {
steps {
withSonarQubeEnv('sonarqube-9.0.1') {
sh "mvn clean install sonar:sonar"
}
}
}
stage( 'Build docker image') {
steps {
sh "docker build -t $registryUrl/hello:${BUILD_NUMBER} ."
}
}
stage('Upload Image to ACR') {
steps{
withCredentials([usernamePassword(credentialsId: 'docker-hub', passwordVariable: 'docker_pass', usernameVariable: 'docker_user')]) {
sh "docker login $registryUrl -u ${docker_user} -p ${docker_pass}"
}
// sh 'docker tag hello:latest $registryUrl/hello:${BUILD_NUMBER}'
sh 'docker push $registryUrl/hello:${BUILD_NUMBER}'
}
}
stage( 'Login to AKS repo') {
steps {
sh 'rm -rf *'
withCredentials([usernamePassword(credentialsId: 'test-tken-v', passwordVariable: 'password', usernameVariable: 'username')]) {
//git remote set-url origin https://venkateshmuddusetty:${password}@github.com/venkateshmuddusetty/test.git
sh '''
git config --global user.name "${username}"
git config --global user.email "[email protected]"
git clone https://${password}@github.com/venkateshmuddusetty/test.git
'''
}
}
}
stage( 'Update to AKS repo') {
steps {
sh '''
cd test/
git branch
rm -rf deployment.yml
cp -r /opt/k8s_deploy/deployment.yml ${WORKSPACE}/test/
sed -i "s|LATESTVERSION|$registryUrl/hello:${BUILD_NUMBER}|g" ${WORKSPACE}/test/deployment.yml
git add deployment.yml
git commit -m "Build_number"
git push -u origin '''
}
}
}
}