-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
69 lines (69 loc) · 2.31 KB
/
Jenkinsfile
File metadata and controls
69 lines (69 loc) · 2.31 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
pipeline {
agent any
options { buildDiscarder(logRotator(numToKeepStr: '1')) }
tools {
maven 'maven3.9.1'
jdk 'jdk11'
}
triggers {
githubPush()
}
environment {
DOCKERHUB_CREDENTIALS = credentials('dockerhub')
}
stages {
stage('Clone Source') {
steps {
cleanWs()
git branch: 'main', changelog: false, poll: false, url: 'https://github.com/norfluxX/Docker-Java-WebApp-DevOps-Pipeline.git'
}
}
stage('Build & QA'){
steps {
withSonarQubeEnv('SonarQube') {
sh "mvn clean verify sonar:sonar \
-Dsonar.projectKey=java-pipeline \
-Dsonar.projectName='java-pipeline' \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.token=sqp_3afa86ea04df49c64459b41af426cc280730c89f"
}
}
}
stage('Copy artifact'){
steps{
sh 'mv target/*.war .'
}
}
stage('DockerHub Login'){
steps{
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
}
}
stage('Build Docker Image'){
steps{
script{
def build_id = sh( script: 'wget -qO- http://localhost:8080/job/Java_Docker/lastSuccessfulBuild/buildNumber', returnStdout: true );
}
sh "echo ${build_id}"
sh """ sed -i '1s/FROM bhikeshk7:.*/FROM bhikeshk7:${build_id}/' Dockerfile """
sh 'docker build -t bhikeshk7/tomcatalpine:${BUILD_NUMBER} -f Dockerfile .'
}
}
stage('Push Image to DockerHub'){
steps{
sh 'docker push bhikeshk7/tomcatalpine:${BUILD_NUMBER}'
}
}
stage('Deploy to the container'){
steps{
sh 'docker ps | grep bhikesh | awk "{print $1}" | xargs docker stop || true '
sh 'docker run -dp 8888:8080 bhikeshk7/tomcatalpine:${BUILD_NUMBER}'
}
}
stage("Send Notification"){
steps{
sh "node /home/ubuntu/Desktop/twilio/wa.js"
}
}
}
}