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 and see the changes right away.

  • Uncaught TypeError: this.props.onDelete is not a function reactjs
  • What is the best way to keep javascript libraries up-to-date in rails?
  • Can I influence the merge strategy used by “recursive” when applying a git stash?
  • Fork file from git repo without cloning the repo
  • Git --force-with-lease with + in branch (refspec)
  • git pull via PHP exec IIS
  • 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?

  • Set file as non-binary in git
  • What files of my project should I put in repo
  • Git - How to fix “corrupted” interactive rebase?
  • Can't commit update-index on Windows
  • How to git clone 'git' metadata only
  • Using a Git hook to create a commit log and add to the current commit
  • 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
    • 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.