Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins after restart runs spec on deleted branches

I use Jenkins with a Github repository, and after restart Jenkins runs spec on all branches, even on those deleted from the repo. How do I make jenkins run specs on only the actual repo branches?

like image 901
Sławosz Avatar asked Jan 05 '12 09:01

Sławosz


1 Answers

This happens as you still have all the branches, tags, etc. in your local repository, client side. In order to avoid using them during your build process, there are few scenarios you might consider:

  1. Jenkins git plugin enables you to run git remote prune before every build. As the documentation for the command is quite specific, it will do exactly what you wanted:

    Deletes all stale tracking branches under . These stale branches have already been removed from the remote repository referenced by , but are still locally available in "remotes/".

    This feature is available at the project configuration page, section Source Code Management, then find Git and your repository definition. Below them you should have an Advanced button, and after clicking it an option named Prune remote branches before build should be visible. Make sure it checked and you should be good to go.

  2. The second option, the one used in my Jenkins and the one I personally prefer, is to use Workspace Cleanup Plugin. This plugin will remove the whole workspace of the given job before or after the project build execution. So this will create a clean, freshly checked-out environment for Your Maven, Ant, [...]* whatever to use for building the project. And yes - it will require a full checkout of the project, which in some cases may actually take quite a while, but it will give 100% stupid-mistakes-free solution in which all the files will be fresh, as developers intended them to be.
like image 183
Łukasz Rżanek Avatar answered Nov 09 '22 09:11

Łukasz Rżanek