Skip to content
Merged
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
65 changes: 58 additions & 7 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pipeline{
agent any
environment{
Docker_tag = getDockerTag()
docker_pws = credentials('docker-password')
}
stages{
stage("Sonar scan"){
Expand Down Expand Up @@ -50,19 +51,69 @@ pipeline{
steps{
script{
sh """
printenv
cp -r ../sample-web-app-pull-request@2/target .
cp -r ../$JOB_BASE_NAME@2/target .
docker build . -t 34.125.26.221:8083/sample-app:$Docker_tag
"""
}
}
}


stage('docker login & push'){
steps{
script{
sh """
docker login -u admin -p $docker_pws 34.125.26.221:8083
docker push 34.125.26.221:8083/sample-app:$Docker_tag
"""
addBadge(icon: 'save.gif', text: 'docker repo', link: 'http://34.125.26.221:8081/#browse/browse:docker-hosted:v2%2Fsample-app')
currentBuild.description = "sample-app:$Docker_tag"
}
}
}

stage('authenticate and prepare k8s manifest files'){
steps{
script{
configFileProvider([configFile(fileId: 'kube-dev-config', variable: 'KUBECONFIG')]) {
sh '''
kubectl get po
final_tag=$(echo $Docker_tag | tr -d ' ')
sed -i "s|TAG|$final_tag|" deployment.yaml
cat deployment.yaml
'''
}
}
}
}

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('deploy to k8s cluster'){
steps{
script{
configFileProvider([configFile(fileId: 'kube-dev-config', variable: 'KUBECONFIG')]) {
sh '''
kubectl apply -f deployment.yaml
'''
}
}
}
}
}

// post {
// always{
// cleanWs()
// }
// }
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
2 changes: 1 addition & 1 deletion 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>2.0</version>
<version>2.0-SNAPSHOT</version>
<name>WebApp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
Expand Down