0

In some jenkins shell command I create new git branch as follow:

git checkout -b new_branch
...
run more commands
..

sometimes running some commands is not successfull and the job exits. Now when I run the job again it says that the branch new_branch already exists.

Is there any option in jenkins to cleans up the locally created branches every time when the job starts or something like that?

Ronald
  • 2,721
  • 8
  • 33
  • 44
  • 1
    I guess you should be looking for git command to list out locally created branches only and then you could iterate over them and run git command to remove branch command against each of the branches. Put this at the beginning of your job, or write the code in a shell script and invoke that script from your job. – Sandeepan Nath May 18 '16 at 13:24
  • 2
    you can clean your workspace before starting... – Daniel Hernández May 18 '16 at 14:32
  • BTW Jenkins-git-plugin uses detached head. You need not clean local branches. – Jayan May 19 '16 at 02:20
  • http://stackoverflow.com/questions/2003505/delete-a-git-branch-both-locally-and-remotely : You may switch master or a temp branch before deleting a branch. – Jayan May 19 '16 at 02:22

1 Answers1

1

2 ways to go about it :

  • Run "git branch -d new_branch" to delete your local branch
  • Clean your workspace before checking out
Dvir669
  • 6,577
  • 1
  • 20
  • 21