Issue
How can I get jenkins git scm integration to run a prune prior to fetch on master?
Problem
On master for a job that runs on a node, Jenkins pipeline job fails to start during workspace fetch. If we run git remote prune origin the problem clears. Master needs to maintain a workspace in order for it to load the jenkins file, determine the node to use and serialize commands back and forth.
The workspace became corrupt in some way related to a ref conflict and I'd like to get jenkins to auto prune to avoid this potential problem.
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to
fetch from [email protected]
error: cannot lock ref 'refs/remotes/origin/user/fix/master/TICKET':
'refs/remotes/origin/user/fix/master' exists;
cannot create 'refs/remotes/origin/user/fix/master/TICKET'
! [new branch] user/fix/master/TICKET -> origin/user/fix/master/TICKET
(unable to update local ref)
How can I get jenkins to auto prune in the master workspace prior to fetch (and perhaps after it too)?
Solution
To avoid this problem on a shared library or any git clone for that matter you can add in some of the pruning options. Given that our shared library can clone from nothing in about 2s we opted for adding Wipe out repository & force clone
option.
Answered By - Peter Kahn
Answer Checked By - Senaida (JavaFixing Volunteer)