fix: Build instruction NPE

This commit is contained in:
Guixian Zhang 2021-01-11 16:03:23 +08:00
parent fce5b691b9
commit 9fafeb7c5b
4 changed files with 14 additions and 6 deletions

View File

@ -207,19 +207,20 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
} }
// 兼容构建指令升级 // 兼容构建指令升级
if (!oldConfig.jobsMigrated3) { if (!oldConfig.jobsMigrated4) {
for (AbstractProject<?, ?> project : Jenkins.getInstance().getAllItems(AbstractProject.class)) { for (AbstractProject<?, ?> project : Jenkins.getInstance().getAllItems(AbstractProject.class)) {
GiteePushTrigger trigger = project.getTrigger(GiteePushTrigger.class); GiteePushTrigger trigger = project.getTrigger(GiteePushTrigger.class);
if (trigger != null) { if (trigger != null) {
if (trigger.getCiSkip()) { if (trigger.getCiSkip()) {
trigger.setBuildInstructionFilterType(BuildInstructionFilterType.CI_SKIP); trigger.setBuildInstructionFilterType(BuildInstructionFilterType.CI_SKIP);
} else { } else if (trigger.getBuildInstructionFilterType() == null) {
trigger.setBuildInstructionFilterType(BuildInstructionFilterType.NONE); trigger.setBuildInstructionFilterType(BuildInstructionFilterType.NONE);
} }
project.save(); project.save();
} }
} }
oldConfig.jobsMigrated3 = true; oldConfig.jobsMigrated3 = false;
oldConfig.jobsMigrated4 = true;
oldConfig.save(); oldConfig.save();
} }
@ -610,6 +611,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
private boolean jobsMigrated = false; private boolean jobsMigrated = false;
private boolean jobsMigrated2 = false; private boolean jobsMigrated2 = false;
private boolean jobsMigrated3 = false; private boolean jobsMigrated3 = false;
private boolean jobsMigrated4 = false;
private String GiteeApiToken; private String GiteeApiToken;
private String giteeHostUrl = ""; private String giteeHostUrl = "";
private boolean ignoreCertificateErrors = false; private boolean ignoreCertificateErrors = false;

View File

@ -85,7 +85,10 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
@Override @Override
protected boolean isCiSkip(NoteHook hook, BuildInstructionFilter buildInstructionFilter) { protected boolean isCiSkip(NoteHook hook, BuildInstructionFilter buildInstructionFilter) {
return hook.getPullRequest() == null ? false : !buildInstructionFilter.isBuildAllow(hook.getPullRequest().getBody()); if (buildInstructionFilter != null && hook.getPullRequest() != null) {
return !buildInstructionFilter.isBuildAllow(hook.getPullRequest().getBody());
}
return false;
} }
@Override @Override

View File

@ -116,7 +116,10 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
@Override @Override
protected boolean isCiSkip(PullRequestHook hook, BuildInstructionFilter buildInstructionFilter) { protected boolean isCiSkip(PullRequestHook hook, BuildInstructionFilter buildInstructionFilter) {
return hook.getPullRequest() == null ? false : !buildInstructionFilter.isBuildAllow(hook.getPullRequest().getBody()); if (buildInstructionFilter != null && hook.getPullRequest() != null) {
return !buildInstructionFilter.isBuildAllow(hook.getPullRequest().getBody());
}
return false;
} }
@Override @Override

View File

@ -41,7 +41,7 @@ class PushHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<PushHook>
@Override @Override
protected boolean isCiSkip(PushHook hook, BuildInstructionFilter buildInstructionFilter) { protected boolean isCiSkip(PushHook hook, BuildInstructionFilter buildInstructionFilter) {
List<Commit> commits = hook.getCommits(); List<Commit> commits = hook.getCommits();
if (commits != null && !commits.isEmpty()) { if (buildInstructionFilter!= null && commits != null && !commits.isEmpty()) {
return !buildInstructionFilter.isBuildAllow(commits.get(commits.size() - 1).getMessage()); return !buildInstructionFilter.isBuildAllow(commits.get(commits.size() - 1).getMessage());
} }
return false; return false;