forked from javahometech/node-app
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathJenkinsfile
More file actions
81 lines (78 loc) · 2.97 KB
/
Jenkinsfile
File metadata and controls
81 lines (78 loc) · 2.97 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
pipeline {
agent {label 'slave1'}
environment{
DOCKER_TAG = getDockerTag()
}
stages{
stage('git clone')
{
steps{
sh'rm -rf node-app'
sh' git clone https://github.com/anilkumarpuli/node-app.git'
}
}
stage('build'){
steps{
sh'mvn clean install'
}
}
stage('Sonarqube') {
environment {
def scannerHome = tool 'sonar';
}
steps {
withSonarQubeEnv('sonar') {
sh "${scannerHome}/bin/sonar-scanner"
}
}
}
//stage('deploy throuh ansible')
// {
//steps{
// sshPublisher(publishers: [sshPublisherDesc(configName: 'ansible_server', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'ansible-playbook copywar.yml', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/home/ansible', remoteDirectorySDF: false, removePrefix: '/home/ansible/workspace/workspace/pipeline/target', sourceFiles: '/home/ansible/workspace/workspace/pipeline/target/vprofile-v1.war')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
// }
// }
//stage('deploy to tomcat')
//{
//steps
// {
//deploy adapters: [tomcat9(credentialsId: 'tomcat', path: '', url: 'http://172.31.44.163:8080')], contextPath: 'anil', war: '**/*.war'
//}
//}
stage('Build Docker Image'){
steps{
sh 'docker images -q -f dangling=true | xargs --no-run-if-empty docker rmi'
sh "docker build . -t anilkumblepuli/java2:${DOCKER_TAG}"
}
}
stage('DockerHub Push'){
steps{
withCredentials([string(credentialsId: 'docker-push', variable: 'dockerhubpwD1')])
{
sh "docker login -u anilkumblepuli -p ${dockerhubpwD1}"
sh "docker push anilkumblepuli/java2:${DOCKER_TAG}"
}
}
}
stage('Deploy to k8s'){
steps{
sh "chmod +x changeTag.sh"
sh "./changeTag.sh ${DOCKER_TAG}"
sshagent(['kops-machine']) {
sh "scp -o StrictHostKeyChecking=no services.yml node-app-pod.yml ubuntu@172.31.14.30:/home/ubuntu/"
script{
try{
sh "ssh ubuntu@172.31.14.30 kubectl apply -f ."
}catch(error){
sh "ssh ubuntu@172.31.14.30 kubectl create -f ."
}
}
}
}
}
}
}
def getDockerTag(){
def tag = sh script: 'git rev-parse HEAD', returnStdout: true
return tag
}