2

Jenkins build is failing with error below error. Kindly help to fix it.

git config --get remote.origin.url # timeout=10 using GIT_ASKPASS to set credentials Setting http proxy: www-proxy.us.oracle.com:80 git fetch --tags --force --progress origin +refs/heads/:refs/remotes/origin/ # timeout=10 hudson.plugins.git.GitException: Command "git fetch --tags --force --progress origin +refs/heads/:refs/remotes/origin/" returned status code 1: stdout: stderr: From https://alm.oraclecorp.com/epm/s/epm_pbcs_15318/scm/strategicmodeling * [new branch] users/aaron.weber/mydevelop -> origin/users/aaron.weber/mydevelop * [new branch] users/abhilash.mund/mydevelop -> origin/users/abhilash.mund/mydevelop error: cannot lock ref 'refs/remotes/origin/users/bill.roper/develop': is at cf9f03f3568e8e7b60918a8fc6e39a3d8d265c42 but expected 5baac24b91a27586748ad1afb6e8142ed7bf568f ! 5baac24b9..02c773ae0 users/bill.roper/develop -> origin/users/bill.roper/develop (unable to update local ref) * [new branch] users/dave.farr/develop -> origin/users/dave.farr/develop

We started deleting the branches and recreating them again with different name and only with small chars. this is working but we are facing issues when owners of branch are not available to do this. Will different user renaming the branch remotely causes any issues like loosing the uncommitted changes of branch owner. Or f there is any other solution please let me know

We want the jenkins build to be successful

jon
  • 213
  • 1
  • 5
  • 18

2 Answers2

0

As mentioned in this answer, try in your Jenkins job first a:

git gc --prune=now
git remote prune origin

The second command will remove references to remote (since deleted) branches in the namespace origin.

Something like:

stage('Checkout') {
    // Update our shared reference repo for all branches/PRs
    dir('..') {
        if (fileExists('yourRepo.git')) {
            dir('yourRepo.git') {
            sh 'git --prune=now'
            sh 'git remote prune origin' // update the clone
            sh 'git prune' // prune to avoid "warning: There are too many unreachable loose objects"
            }
        } else {
            sh 'git clone --mirror /url/to/yourRepo.git' // create a mirror
                }
        }
    }
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • A more targeted approach: `git update-ref -d refs/remotes/origin/users/bill.roper/develop/` – VonC May 13 '19 at 04:44
  • I am getting error as $ git update-ref -d refs/remotes/origin/users/bill.roper/develop/ error: refusing to update ref with bad name 'refs/remotes/origin/users/bill.roper/develop/' – jon May 13 '19 at 06:26
  • @jon And the other commands? Would they be enough to make your problem go away? – VonC May 13 '19 at 06:28
  • Could you please tell me where to add the other commands in this jenkins pipeline script :-- env.EPBCSMODULES_BRANCH_NAME="develop" def downloadLocationForEPBCS="epmpbcs-release-local/Platform/EPBCSModules/${EPBCSMODULES_BRANCH_NAME}/latest" if ("${BRANCH_NAME}"=="develop") { properties( [ pipelineTriggers([cron('H 4 * * 2,4')]), ] ) } else { properties( [ pipelineTriggers([cron('')]), ] ) } stage('Checkout') { scmVars = checkout scm } – jon May 13 '19 at 07:34
  • @jon Sure: I have edited the answer to add an example, modeled after https://github.com/appcelerator/titanium_mobile/blob/57a418f653c4394666dc472f5de6666fd16e1504/Jenkinsfile#L133-L145 – VonC May 13 '19 at 09:29
  • the build is failing at very beginnig stage > git config --get remote.origin.url # timeout=10 > git fetch --tags --force --progress origin +refs/heads/*:refs/remotes/origin/* # timeout=10 hudson.plugins.git.GitException: Command "git fetch --tags --force --progress origin +refs/heads/*:refs/remotes/origin/*" returned status code 1: stdout: stde – jon May 13 '19 at 15:50
  • @jon Can you edit your question with the full error message? – VonC May 13 '19 at 19:10
  • I have edited the question. Build is successful after deleting the error branch. But the problem is we can't keep on ask developers to delete their branches – jon May 14 '19 at 04:09
  • @jon Then another approach would be to use a dedicated Git repo (dedicated to be used only by Jenkins), where Jenkins would start by fetching from your dev repo only the branch to build, ignoring any other problematic branch. – VonC May 14 '19 at 04:34
  • But this is a multi branch pipeline job. is there any way to use only the branch to build – jon May 14 '19 at 05:05
  • @jon Yes, by monitoring the original repo as you do right now, but by fetching only the branch you need to the dedicated repo, and triggering a dedicated job on that branch of that dedicated repository. – VonC May 14 '19 at 05:06
  • I am using scripted pipeline. could you please tell me how to do that – jon May 14 '19 at 10:08
0

in terminal

"cd /.git/refs/remotes/origin"

do "ls", you will see some branches and HEAD

Remove the branch you think has the problem

"rm branchname"

If it did not work, delete all branches/HEAD

you may wana pull

jon
  • 213
  • 1
  • 5
  • 18