Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 96 additions & 66 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,79 +1,109 @@
currentBuild.displayName = "Final_Demo # "+currentBuild.number

def getDockerTag(){
def getDockerTag(){
def tag = sh script: 'git rev-parse HEAD', returnStdout: true
return tag
}

}

pipeline{
agent any
environment{
Docker_tag = getDockerTag()
}

stages{
pipeline {
agent any

environment{
Docker_tag = getDockerTag()
Docker_Creds = credentials('dockerhub-creds')
}

stage('Quality Gate Statuc Check'){
stages {
stage('static code anaylysis'){

agent{
docker{
image 'maven:3.6.0'
}
}

agent {
docker {
image 'maven'
args '-v $HOME/.m2:/root/.m2'
steps {
script{
withSonarQubeEnv(credentialsId: 'sonartoken') {
sh 'printenv'
sh "mvn sonar:sonar"
}

// timeout(5){
// def qg = waitForQualityGate()
// if (qg.status != 'OK'){
// error "code didnt met qulaity gate"
// }
// }

}
}
steps{
script{
withSonarQubeEnv('sonarserver') {
sh "mvn sonar:sonar"
}
timeout(time: 1, unit: 'HOURS') {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
sh "mvn clean install"
}
}
}

stage('build') {

agent{
docker{
image 'maven:3.6.0'
args '-v /root/.m2:/root/.m2'
}
}

steps{
script{
sh "mvn clean install"
}
}
}

stage('docker build & docker push') {
steps{
script{
sh """
cp -r ../complete-pipeline@2/target .
docker build . -t deekshithsn/webapp-demo:$Docker_tag
docker login -u $Docker_Creds_USR -p $Docker_Creds_PSW
docker push deekshithsn/webapp-demo:$Docker_tag
"""
currentBuild.description = "$Docker_tag"
addBadge(icon: 'save.gif' , link: 'https://hub.docker.com/repository/docker/deekshithsn/webapp-demo/tags')
}
}
}

stage('build')
{
steps{
script{
sh 'cp -r ../devops-training@2/target .'
sh 'docker build . -t deekshithsn/devops-training:$Docker_tag'
withCredentials([string(credentialsId: 'docker_password', variable: 'docker_password')]) {

sh 'docker login -u deekshithsn -p $docker_password'
sh 'docker push deekshithsn/devops-training:$Docker_tag'
}
}
stage('approval stage') {
steps{
script{
timeout(5){
// mail bcc: '', body: "<br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL de build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "${currentBuild.result} CI: Project name -> ${env.JOB_NAME}", to: "deekshithsn@gmail.com";
input( message: "Deploy ${params.project_name}?", ok: 'Deploy')
}
}

stage('ansible playbook'){
steps{
script{
sh '''final_tag=$(echo $Docker_tag | tr -d ' ')
echo ${final_tag}test
sed -i "s/docker_tag/$final_tag/g" deployment.yaml
'''
ansiblePlaybook become: true, installation: 'ansible', inventory: 'hosts', playbook: 'ansible.yaml'
}
}
}



}





}
}
}
}

stage('deploy stage'){
steps{
script{
sh '''
final_tag=$(echo $Docker_tag | tr -d ' ')
sed -i "s;IMAGE_NAME;deekshithsn/webapp-demo:$final_tag;" deployment.yaml
cat deployment.yaml
'''
}
}
}


stage('deploy to k8s cluster'){
steps{
script{
configFileProvider([configFile(fileId: 'kube-dev-config', variable: 'KUBECONFIG')]) {
sh '''
kubectl apply -f deployment.yaml
'''
}
}
}
}

}
}
2 changes: 1 addition & 1 deletion deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
spec:
containers:
- name: devops-training
image: deekshithsn/devops-training:docker_tag
image: IMAGE_NAME
command: ["/bin/sh"]
args: ["-c","sh /usr/local/tomcat/bin/startup.sh;while true; do echo hello; sleep 10;done"]
ports:
Expand Down
5 changes: 5 additions & 0 deletions src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
<p>Jenkins is a free and open source automation server. Jenkins helps to automate the non-human part of the software development process, with continuous integration and facilitating technical aspects of continuous delivery</p>
<p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p>
</div>
<div class="col-md-4">
<h2>Kubernetes</h2>
<p>Kubernetes is a free and open source automation server. Jenkins helps to automate the non-human part of the software development process, with continuous integration and facilitating technical aspects of continuous delivery</p>
<p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p>
</div>
<div class="col-md-4">
<h2>Maven</h2>
<p>Maven is a build automation tool used primarily for Java projects. Maven can also be used to build and manage projects written in C#, Ruby, Scala, and other languages.</p>
Expand Down