Jenkins deploy per branch

I have a PHP application that will be using Jenkins and GitHub to automatically deploy every time when pushed.

I am working on a branch so if I push any changes I want to deploy to branch.test.com and see the changes right away.

  • Revert Git pull
  • How does Capistrano work by default?
  • Switching branches in Git doesn't remove directories
  • Git switching between commits
  • What are some methods for keeping track of Xcode projects in source control?
  • git pre-receive hook original directory
  • I am trying to use “Execute Shell” in Jenkins so after build, it finds out which branch (‘master’ or ‘develop’) is updated and copies it to the www folder to reflect the changes.

    Am I on the right track?

  • git branch -f and git checkout in one step
  • Teamcity to github List remote refs failed not authorized jgit
  • Tools for Maintaining Branches in SVN
  • How to give friend access to git repository without giving command line access?
  • Git for Mac OS X 10.4
  • how to add ssh public key to a specific git repo
  • 2 Solutions collect form web for “Jenkins deploy per branch”

    Yes, you are on the right track. Jenkins can be used for Continuous Delivery (CD) and doing build/deploy/test process per branch is a good practice.

    I suggest you to use separate jobs for each branch. Even Jenkins Best Practices page says this:

    One of advantages of using CI tools is to detect problems early in the development lifecycle. Setting up a different job/project for each branch you create will help to maximize the benefit of detecting problems early as part of supporting parallel development efforts and reducing risk.

    Usually, project grows and becomes to have a lot of branches and at some point you will need to automate a process of creation a bunch of jobs for each branch. Here are few articles that will help:

    • Auto-create Jenkins build jobs for new feature
      branches
    • Jenkins build and deploy script per Github branch
    • Jenkins autojobs
    • Jenkins DSL Plugin

    Answer by Vitalii Elenhaupt is good.
    I just want to elaborate more on what I was doing.
    I’ve found my own answer while I’m digging Jenkins.

    In “Excute shell” Using following code will deploy files to “branch” in own server in this case.

    echo ${GIT_BRANCH##origin/}
    rm -rf /home/www/${GIT_BRANCH##origin/}/* > /dev/null
    rsync -av --exclude='.git' ${WORKSPACE}/ /home/www/${GIT_BRANCH##origin/}
    

    If it gets busier then I might create a separate job for each branch as Vitalii Elenhaupt suggested.

    Git Baby is a git and github fan, let's start git clone.