Skip to content

Commit 44c802e

Browse files
committed
intial jenkins file
1 parent 5af954f commit 44c802e

File tree

1 file changed

+60
-67
lines changed

1 file changed

+60
-67
lines changed

Jenkinsfile

Lines changed: 60 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,72 @@
1-
currentBuild.displayName = "Final_Demo # "+currentBuild.number
2-
3-
def getDockerTag(){
1+
def getDockerTag(){
42
def tag = sh script: 'git rev-parse HEAD', returnStdout: true
53
return tag
6-
}
7-
4+
}
85

9-
pipeline{
10-
agent any
11-
environment{
12-
Docker_tag = getDockerTag()
13-
}
14-
15-
stages{
6+
pipeline {
7+
agent any
168

9+
environment{
10+
Docker_tag = getDockerTag()
11+
Docker_Creds = credentials('dockerhub-creds')
12+
}
1713

18-
stage('Quality Gate Statuc Check'){
14+
stages {
15+
stage('static code anaylysis'){
16+
17+
agent{
18+
docker{
19+
image 'maven:3.6.0'
20+
}
21+
}
1922

20-
agent {
21-
docker {
22-
image 'maven'
23-
args '-v $HOME/.m2:/root/.m2'
23+
steps {
24+
script{
25+
withSonarQubeEnv(credentialsId: 'sonartoken') {
26+
sh 'printenv'
27+
sh "mvn sonar:sonar"
2428
}
29+
30+
// timeout(5){
31+
// def qg = waitForQualityGate()
32+
// if (qg.status != 'OK'){
33+
// error "code didnt met qulaity gate"
34+
// }
35+
// }
36+
}
2537
}
26-
steps{
27-
script{
28-
withSonarQubeEnv('sonarserver') {
29-
sh "mvn sonar:sonar"
30-
}
31-
timeout(time: 1, unit: 'HOURS') {
32-
def qg = waitForQualityGate()
33-
if (qg.status != 'OK') {
34-
error "Pipeline aborted due to quality gate failure: ${qg.status}"
35-
}
36-
}
37-
sh "mvn clean install"
38-
}
39-
}
38+
}
39+
40+
stage('build') {
41+
42+
agent{
43+
docker{
44+
image 'maven:3.6.0'
45+
args '-v /root/.m2:/root/.m2'
4046
}
47+
}
4148

49+
steps{
50+
script{
51+
sh "mvn clean install"
52+
}
53+
}
54+
}
4255

56+
stage('docker build & docker push') {
57+
steps{
58+
script{
59+
sh """
60+
cp -r ../complete-pipeline@2/target .
61+
docker build . -t deekshithsn/webapp-demo:$Docker_tag
62+
docker login -u $Docker_Creds_USR -p $Docker_Creds_PSW
63+
docker push deekshithsn/webapp-demo:$Docker_tag
64+
"""
65+
currentBuild.description = "$Docker_tag"
66+
addBadge(icon: 'save.gif' , link: 'https://hub.docker.com/repository/docker/deekshithsn/webapp-demo/tags')
67+
}
68+
}
69+
}
4370

44-
stage('build')
45-
{
46-
steps{
47-
script{
48-
sh 'cp -r ../devops-training@2/target .'
49-
sh 'docker build . -t deekshithsn/devops-training:$Docker_tag'
50-
withCredentials([string(credentialsId: 'docker_password', variable: 'docker_password')]) {
51-
52-
sh 'docker login -u deekshithsn -p $docker_password'
53-
sh 'docker push deekshithsn/devops-training:$Docker_tag'
54-
}
55-
}
56-
}
57-
}
58-
59-
stage('ansible playbook'){
60-
steps{
61-
script{
62-
sh '''final_tag=$(echo $Docker_tag | tr -d ' ')
63-
echo ${final_tag}test
64-
sed -i "s/docker_tag/$final_tag/g" deployment.yaml
65-
'''
66-
ansiblePlaybook become: true, installation: 'ansible', inventory: 'hosts', playbook: 'ansible.yaml'
67-
}
68-
}
69-
}
70-
71-
72-
73-
}
74-
75-
76-
77-
78-
79-
}
71+
}
72+
}

0 commit comments

Comments
 (0)