Jenkins的pipeline如何“修剪陈旧的远程跟踪分支”?

Jenkins出现了陈旧的分支和远程git服务器有冲突, 如下:

ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from git@XXX
	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:894)
	at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1161)
	at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1192)
	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:124)
	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:93)
	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:80)
	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- git@XXX +refs/heads/*:refs/remotes/origin/*" returned status code 1:
stdout: 
stderr: error: cannot lock ref 'refs/remotes/origin/xxx': 'refs/remotes/origin/xxx' exists; cannot create 'refs/remotes/origin/xxx'
From xxx
 ! [new branch]      xxx -> origin/xxx  (unable to update local ref)
error: some local refs could not be updated; try running
 'git remote prune xxx' to remove any old, conflicting branches

	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2174)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1866)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:78)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:547)
	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:892)
	... 11 more

在网上找了很多方法都不行, 去国外网站找了一圈也没有答案, 想了想, Jenkins的git流水线插件不应该做得那么搓, 绝对会把这个问题考虑进去了, 从生产流水线语法入手查查有没有更好的方法:

流水线语法的入口有2个地方:

1)

2) 

进去之后呢, 如下:

看的时候感觉上面部门, 就是一些git的常用配置, 感觉都没有特别, 再往下一看:

没错, 就是它(PruneStaleBranch), 可以修建修剪陈旧的远程跟踪分支, 在这里补上, 重新点击构建, 成功了:

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值