need to deploy in multiple branches

23 views
Skip to first unread message

robert....@ithands.biz

unread,
Nov 27, 2018, 6:55:47 AM11/27/18
to Jenkins Users
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
                   git 'https://github.com/raj1rana/mongoDB-docker.git'

                   }
               stage('pull-staging'){
                       //pulling staging from the repo
                    git branch: 'staging', url: 'https://github.com/raj1rana/mongoDB-docker.git'
                   }
               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',
                     from: 'xx...@yyyyy.com',
                     replyTo: 'xx...@yyyy.com',
                     subject: 'project build successful',
                     to: 'yy...@yyyy.com'
                 }
  
       }
       catch (err) {

        currentBuild.result = "FAILURE"

            mail body: "project build error is here: ${env.BUILD_URL}" ,
            from: 'xx...@yyyy.com',
            replyTo: 'yy...@yyyy.com',
            subject: 'project build failed',
            to: 'zz...@yyyyy.com'

        throw err
    }

}
    

robert....@ithands.biz

unread,
Nov 27, 2018, 6:57:25 AM11/27/18
to Jenkins Users

Jan Monterrubio

unread,
Nov 27, 2018, 8:48:08 AM11/27/18
to jenkins...@googlegroups.com
You could have a jenkinsfile lube with the repository and check the BRANCH environment variable to find out where you’re building from. 

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/9a3e3b37-0da7-467e-8f05-ecb7458bcf7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

robert....@ithands.biz

unread,
Nov 27, 2018, 9:01:58 AM11/27/18
to Jenkins Users
Thanks for reachibg out how do
I add those variables if there is an article please share

Jan Monterrubio

unread,
Nov 27, 2018, 9:10:37 AM11/27/18
to jenkins...@googlegroups.com
A quick search found this: 

Once I get to a computer I’ll do some more searching since finding text on a phone is hard :)

On Tue, Nov 27, 2018 at 08:02 <robert....@ithands.biz> wrote:
Thanks for reachibg out how do
 I add those variables if there is an article please share

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Jan Monterrubio

unread,
Nov 27, 2018, 11:20:20 AM11/27/18
to jenkins...@googlegroups.com

Ajay Sharma

unread,
Nov 27, 2018, 12:53:56 PM11/27/18
to jenkins...@googlegroups.com
I am also searching, by tomorrow I will reply.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Robert Rajendra

unread,
Nov 27, 2018, 8:48:26 PM11/27/18
to jenkins...@googlegroups.com

Ajay Sharma

unread,
Nov 27, 2018, 10:05:28 PM11/27/18
to jenkins...@googlegroups.com
use this for master only

if (!env.CHNAGE_ID && env.BRANCH_NAME == 'master')
{  

  }


Reply all
Reply to author
Forward
0 new messages