Skip to content

Commit

Permalink
Update Jenkinsfile
Browse files Browse the repository at this point in the history
  • Loading branch information
javahometech authored Sep 11, 2018
1 parent edf8684 commit 0f1e890
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
node{
try{
node{
properties([parameters([choice(choices: ['master', 'dev', 'qa', 'staging'], description: 'Choose branch to build and deploy', name: 'gitBranch')]), pipelineTriggers([pollSCM('')])])
stage('Git Checkout'){
git credentialsId: 'git-javahometech',
url: 'https://github.com/javahometech/my-app',
branch: "master"
}

stage('Maven Build'){
def mvnHome = tool name: 'maven3', type: 'maven'
sh "${mvnHome}/bin/mvn clean package"
}
git credentialsId: 'github',
url: 'https://github.com/javahometech/my-app',
branch: "${params.gitBranch}"
}

stage('Sonar Analysis'){
withCredentials([string(credentialsId: 'sonar-token', variable: 'sonarToken')]) {
def mvnHome = tool name: 'maven3', type: 'maven'
def sonarUrl = 'http://172.31.25.28:9000'
echo("${mvnHome}/bin/mvn sonar:sonar -Dsonar.host.url=${sonarUrl} -Dsonar.login=${sonarToken}")
sh "${mvnHome}/bin/mvn sonar:sonar -Dsonar.host.url=${sonarUrl} -Dsonar.login=${sonarToken}"
}
stage('Maven Build'){
sh 'mvn clean package'
}
stage('Deploy to Dev'){
sh 'mv target/*.war target/myweb.war'
sshagent(['tomcat-dev']) {
sh 'ssh [email protected] rm -rf /opt/tomcat8/webapps/myweb*'
sh 'scp target/myweb.war [email protected]:/opt/tomcat8/webapps/'
sh 'ssh [email protected] sudo service tomcat restart'
}
slackSend channel: '#devops-2',
color: 'good',
message: "Job - ${env.JOB_NAME}, Completed successfully Build URL is ${env.BUILD_URL}"


}
}

}catch(error){
slackSend channel: '#devops-2',
color: 'danger',
message: "Job - ${env.JOB_NAME}, Failed, Build URL is ${env.BUILD_URL}"
error 'Something wrong'
}

0 comments on commit 0f1e890

Please sign in to comment.