Skip to content
Open

B2 #21

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
117 changes: 37 additions & 80 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,99 +1,56 @@
pipeline {
agent none
tools{
jdk 'myjava'
maven 'mymaven'
}
environment{
IMAGE_NAME='devopstrainer/java-mvn-privaterepos:$BUILD_NUMBER'
DEV_SERVER_IP='ec2-user@13.233.245.74'
APP_NAME='java-mvn-app'
agent any

parameters{
string(name:'roshu' ,defaultValue:'Test' ,description: 'version to deploy')
booleanParam(name: 'ExecuteTest', defaultValue: true, description: 'head of the family')
choice(name: 'appversion', choices: ['manadev', 'nandi', 'parvathi'] )
}

stages {
stage('COMPILE') {
agent any
tools{
jdk 'myjava'
maven 'mymaven'
}
stage('compile') {
steps {
script{
echo "COMPILING THE CODE"
git 'https://github.com/preethid/addressbook.git'
tool name: 'mymaven', type: 'maven'

sh 'mvn compile'
script {
echo 'compile the code'
echo "roshan garu: ${params.roshu}"
}
}
}
stage('UNITTEST'){
agent any
steps {
script{
echo "RUNNING THE UNIT TEST CASES"
sh 'mvn test'
}
stage('unit test') {
when {
expression {
params.ExecuteTest == true
}

}
post{
always{
junit 'target/surefire-reports/*.xml'
steps {
script {
echo 'test the code'
}
}
}
stage('PACKAGE+BUILD DOCKER IMAGE ON BUILD SERVER'){
agent any
steps{
script{
sshagent(['DEV_SERVER']) {
withCredentials([usernamePassword(credentialsId: 'docker-hub', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
echo "PACKAGING THE CODE"
sh "scp -o StrictHostKeyChecking=no server-script.sh ${DEV_SERVER_IP}:/home/ec2-user"
sh "ssh -o StrictHostKeyChecking=no ${DEV_SERVER_IP} 'bash ~/server-script.sh'"
sh "ssh ${DEV_SERVER_IP} sudo docker build -t ${IMAGE_NAME} /home/ec2-user/addressbook"
sh "ssh ${DEV_SERVER_IP} sudo docker login -u $USERNAME -p $PASSWORD"
sh "ssh ${DEV_SERVER_IP} sudo docker push ${IMAGE_NAME}"
}
}
}
stage('package') {
steps {
script {
echo 'package the code'
echo "packaging the code versio ${params.shiva}"
}
}
}
stage("Provision deploy server with TF"){
environment{
AWS_ACCESS_KEY_ID =credentials("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY=credentials("AWS_SECRET_ACCESS_KEY")
stage('deploy') {
input {
message "select the version to deploy"
ok "version selected"
parameters {
choice(name: 'newversion', choices: ['1', '2', '3'])
}
agent any
steps{
script{
dir('terraform'){
sh "terraform init"
sh "terraform apply --auto-approve"
EC2_PUBLIC_IP = sh(
script: "terraform output ip",
returnStdout: true
).trim()
}
}
}
}
stage('DEPLOY ON EC2 instance'){
agent any
steps{
script{
echo "RUN THE APP ON ec2 instance"
echo "Waiting for ec2 instance to initialise"
sleep(time: 90, unit: "SECONDS")
echo "Deploying the app to ec2-instance provisioned bt TF"
echo "${EC2_PUBLIC_IP}"
sshagent(['DEV_SERVER']) {
withCredentials([usernamePassword(credentialsId: 'docker-hub', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
sh "ssh -o StrictHostKeyChecking=no ec2-user@${EC2_PUBLIC_IP} sudo docker login -u $USERNAME -p $PASSWORD"
sh "ssh ec2-user@${EC2_PUBLIC_IP} sudo docker run -itd -p 8080:8080 ${IMAGE_NAME}"

steps {
script {
echo 'deploy the app'

}
}
}
}}
}

}
}
3 changes: 3 additions & 0 deletions mahabharat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

om nama shivaya
hara hara shambho
1 change: 1 addition & 0 deletions nani
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nani
2 changes: 2 additions & 0 deletions tesssst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
malli test tesssst
inko test
1 change: 1 addition & 0 deletions test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
1 change: 1 addition & 0 deletions webhook tessst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
webhok tessssss