Hi Team i want to deploy to the staging only when the code is pushed to staging and to master only when the code is pushed to master Please help that what can i do with the script that i made to achieve that
node{
currentBuild.result = "SUCCESS"
try {
stage('Pull-msater') {
// pulling master from the repo
}
stage('pull-staging'){
//pulling staging from the repo
}
stage('deploy-staging') {
//deploy to staging server
sh 'rsync -avz -e ssh --exclude .git /var/lib/jenkins/workspace/pipeline-test/ user@IP:/home/ubuntu/Stage/'
}
stage('deploy-production'){
//deploy to production server
sh 'rsync -avz -e ssh --exclude .git /var/lib/jenkins/workspace/pipeline-test/ user@IP:/home/ubuntu/master'
}
stage('mail fail/sucess'){
mail body: 'project build successful',
subject: 'project build successful',
}
}
catch (err) {
currentBuild.result = "FAILURE"
mail body: "project build error is here: ${env.BUILD_URL}" ,
subject: 'project build failed',
throw err
}
}