Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
89 changes: 26 additions & 63 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,42 +1,35 @@
def getDockerTag(){
def tag = sh script: 'git rev-parse --short HEAD', returnStdout: true
return tag
}
def getDockerTag(){
def tag = sh script: 'git rev-parse --short HEAD', returnStdout: true
return tag
}

pipeline{
agent any
environment{
Docker_tag = getDockerTag()
docker_login = credentials('public-docker-auth')
docker_pws = credentials('docker-hub-password')
}
stages{
stage("static code analysis"){
stage("Sonar scan"){
agent {
docker {
image 'maven'
args '-v $HOME/.m2:/root/.m2'
args '-v /root/.m2:/root/.m2'
}
}
steps{
script{
withSonarQubeEnv(credentialsId: 'sonar-qube-token') {
sh "mvn sonar:sonar"
}
timeout(5){
def qg = waitForQualityGate()
if (qg.status != 'OK'){
error "code didnt met qulaity gate"
}
}
sh "echo executing sonar scan"
// sh "sleep 90"
}
}
}

stage('build'){
stage('build the application'){
agent {
docker {
image 'maven'
args '-v $HOME/.m2:/root/.m2'
args '-v /root/.m2:/root/.m2'
}
}
steps{
Expand All @@ -47,75 +40,45 @@ pipeline{
}

stage('docker build'){
steps {
steps{
script{
sh """
pwd
ls -la
cp -r ../backend-app@2/target .
docker build . -t deekshithsn/webapp:$Docker_tag
docker build . -t deekshithsn/java-app-hbc:$Docker_tag
"""
currentBuild.description = "deekshithsn/webapp:$Docker_tag"
}
}
}

stage('docker upload'){

stage('docker login & push'){
steps{
script{
sh """
docker login -u $docker_login_USR -p $docker_login_PSW
docker push deekshithsn/webapp:$Docker_tag
docker login -u deekshithsn -p $docker_pws
docker push deekshithsn/java-app-hbc:$Docker_tag
"""
addBadge(icon: 'info.gif', text: 'docker registry', link: 'https://hub.docker.com/repository/docker/deekshithsn/webapp/general')
addBadge(icon: 'save.gif', text: 'docker repo', link: 'https://hub.docker.com/repository/docker/deekshithsn/java-app-hbc')
currentBuild.description = "deekshithsn/java-app-hbc:$Docker_tag"
}
}
}

stage('approval from managers'){
input {
message "do you want to procced for deployment?"
ok "Procced?"
submitter "alice,bob"
parameters {
string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')
}
}
steps{
script{
sh "echo Approved!!!!"
}
}
}

stage('prepare deplyment file'){
stage('deploy the application'){
steps{
script{
sh '''
final_tag=$(echo $Docker_tag | tr -d ' ')
sed -i "s|TAG|$final_tag|" deployment.yaml
cat deployment.yaml
'''
}
}
}

stage('authenticate & deploy'){
steps{
script{
sh"""
export KUBECONFIG=/opt/config
kubectl get po
kubectl apply -f deployment.yaml
sh """
docker rm $( docker stop $( docker ps -aq))
docker run -d -p 9000:8080 deekshithsn/java-app-hbc:$Docker_tag
"""
}
}
}

}

post{
post {
always{
cleanWs()
}
}
}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

```
mvn clean package
and build the instruction .
```

# Deploy instruction

Deploy ```target/WebApp.war``` on Tomcat properly for better experience.



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/webapp:TAG
image: 34.125.26.221/sample-app:TAG
command: ["/bin/sh"]
args: ["-c","sh /usr/local/tomcat/bin/startup.sh;while true; do echo hello; sleep 10;done"]
ports:
Expand Down
16 changes: 14 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>lu.amazon.aws.demo</groupId>
<artifactId>WebApp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
<name>WebApp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
Expand All @@ -30,4 +30,16 @@
</plugin>
</plugins>
</build>
</project>

<distributionManagement>
<snapshotRepository>
<id>nexusdeploymentrepo</id>
<url>http://34.125.26.221:8081/repository/maven-hosted-snapshot/</url>
</snapshotRepository>
<repository>
<id>nexusdeploymentrepo</id>
<url>http://34.125.26.221:8081/repository/maven-hosted-release/</url>
</repository>
</distributionManagement>

</project>