修复git仓库与触发仓库不一致导致构建失败的问题

This commit is contained in:
yashin 2020-08-05 12:01:46 +08:00
parent d0a31c7261
commit ea04e83e7a
5 changed files with 7 additions and 22 deletions

View File

@ -84,26 +84,11 @@ public abstract class AbstractWebHookTriggerHandler<H extends WebHook> implement
protected abstract BuildStatusUpdate retrieveBuildStatusUpdate(H hook);
protected URIish retrieveUrIish(WebHook hook, GitSCM gitSCM) {
if (gitSCM == null) {
return null;
}
List<URIish> uris = new ArrayList<URIish>();
protected URIish retrieveUrIish(WebHook hook) {
try {
if (hook.getRepository() != null) {
uris.add(new URIish(hook.getRepository().getUrl()));
uris.add(new URIish(hook.getRepository().getGitHttpUrl()));
uris.add(new URIish(hook.getRepository().getGitSshUrl()));
}
// uri 需与当前项目仓库个url一致避免触发多个构建
for (RemoteConfig remote : gitSCM.getRepositories()) {
for (URIish remoteURL : remote.getURIs()) {
for (URIish uri : uris) {
if (remoteURL.equals(uri)) {
return uri;
}
}
}
return new URIish(hook.getRepository().getUrl());
}
} catch (URISyntaxException e) {
LOGGER.log(Level.WARNING, "could not parse URL");

View File

@ -125,7 +125,7 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
@Override
protected RevisionParameterAction createRevisionParameter(NoteHook hook, GitSCM gitSCM) throws NoRevisionToBuildException {
return new RevisionParameterAction(retrieveRevisionToBuild(hook), retrieveUrIish(hook, gitSCM));
return new RevisionParameterAction(retrieveRevisionToBuild(hook), retrieveUrIish(hook));
}
@Override

View File

@ -131,7 +131,7 @@ class PipelineHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pipel
@Override
protected RevisionParameterAction createRevisionParameter(PipelineHook hook, GitSCM gitSCM) throws NoRevisionToBuildException {
return new RevisionParameterAction(retrieveRevisionToBuild(hook), retrieveUrIish(hook, gitSCM));
return new RevisionParameterAction(retrieveRevisionToBuild(hook), retrieveUrIish(hook));
}
@Override

View File

@ -189,7 +189,7 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
@Override
protected RevisionParameterAction createRevisionParameter(PullRequestHook hook, GitSCM gitSCM) throws NoRevisionToBuildException {
return new RevisionParameterAction(retrieveRevisionToBuild(hook), retrieveUrIish(hook, gitSCM));
return new RevisionParameterAction(retrieveRevisionToBuild(hook), retrieveUrIish(hook));
}
@Override

View File

@ -115,7 +115,7 @@ class PushHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<PushHook>
@Override
protected RevisionParameterAction createRevisionParameter(PushHook hook, GitSCM gitSCM) throws NoRevisionToBuildException {
return new RevisionParameterAction(retrieveRevisionToBuild(hook, gitSCM), retrieveUrIish(hook, gitSCM));
return new RevisionParameterAction(retrieveRevisionToBuild(hook, gitSCM), retrieveUrIish(hook));
}
@Override