支持 [ci-build] 指令触发构建

This commit is contained in:
Guixian Zhang 2020-12-28 17:48:50 +08:00
parent d8badc62f1
commit 5e5eec28d3
20 changed files with 183 additions and 46 deletions

View File

@ -111,10 +111,6 @@ public class PushHook extends WebHook {
this.project = project;
}
public void setRepository(Project project) {
this.project = project;
}
public List<Commit> getCommits() {
return commits;
}

View File

@ -74,7 +74,8 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
private boolean triggerOnTestedPullRequest = false;
private boolean triggerOnNoteRequest = true;
private String noteRegex = "";
private boolean ciSkip = true;
private transient boolean ciSkip = true;
private BuildInstructionFilterType buildInstructionFilterType;
private boolean skipWorkInProgressPullRequest;
private boolean ciSkipFroTestNotRequired;
private boolean skipLastCommitHasBeenBuild;
@ -113,6 +114,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
boolean triggerOnClosedPullRequest,
boolean triggerOnNoteRequest, String noteRegex,
boolean skipWorkInProgressPullRequest, boolean ciSkip,
BuildInstructionFilterType buildInstructionFilterType,
boolean setBuildDescription, boolean addNoteOnPullRequest, boolean addCiMessage, boolean addVoteOnPullRequest,
boolean acceptPullRequestOnSuccess, BranchFilterType branchFilterType,
String includeBranchesSpec, String excludeBranchesSpec, String targetBranchRegex,
@ -127,6 +129,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
this.noteRegex = noteRegex;
this.triggerOnPipelineEvent = triggerOnPipelineEvent;
this.ciSkip = ciSkip;
this.buildInstructionFilterType = buildInstructionFilterType;
this.skipWorkInProgressPullRequest = skipWorkInProgressPullRequest;
this.setBuildDescription = setBuildDescription;
this.addNoteOnPullRequest = addNoteOnPullRequest;
@ -193,6 +196,24 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
oldConfig.jobsMigrated2 = true;
oldConfig.save();
}
// 兼容构建指令升级
if (!oldConfig.jobsMigrated3) {
for (AbstractProject<?, ?> project : Jenkins.getInstance().getAllItems(AbstractProject.class)) {
GiteePushTrigger trigger = project.getTrigger(GiteePushTrigger.class);
if (trigger != null) {
if (trigger.getCiSkip()) {
trigger.setBuildInstructionFilterType(BuildInstructionFilterType.CI_SKIP);
} else {
trigger.setBuildInstructionFilterType(BuildInstructionFilterType.NONE);
}
project.save();
}
}
oldConfig.jobsMigrated3 = true;
oldConfig.save();
}
}
public boolean getAddNoteOnPullRequest() { return addNoteOnPullRequest; }
@ -219,8 +240,8 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
public boolean isTriggerOnApprovedPullRequest() {
return triggerOnApprovedPullRequest;
}
}
public boolean isTriggerOnClosedPullRequest() {
return triggerOnClosedPullRequest;
}
@ -243,6 +264,10 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
return ciSkip;
}
public BuildInstructionFilterType getBuildInstructionFilterType() {
return buildInstructionFilterType;
}
public boolean getCiSkipFroTestNotRequired() {
return ciSkipFroTestNotRequired;
}
@ -299,7 +324,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
public void setTriggerOnPush(boolean triggerOnPush) {
this.triggerOnPush = triggerOnPush;
}
@DataBoundSetter
public void setTriggerOnApprovedPullRequest(boolean triggerOnApprovedPullRequest) {
this.triggerOnApprovedPullRequest = triggerOnApprovedPullRequest;
@ -340,6 +365,11 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
this.ciSkip = ciSkip;
}
@DataBoundSetter
public void setBuildInstructionFilterType(BuildInstructionFilterType buildInstructionFilterType) {
this.buildInstructionFilterType = buildInstructionFilterType;
}
@DataBoundSetter
public void setCiSkipFroTestNotRequired(boolean ciSkipFroTestNotRequired) {
this.ciSkipFroTestNotRequired = ciSkipFroTestNotRequired;
@ -448,7 +478,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
if (pushHookTriggerHandler == null) {
initializeTriggerHandler();
}
pushHookTriggerHandler.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
pushHookTriggerHandler.handle(job, hook, buildInstructionFilterType, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
}
// executes when the Trigger receives a pull request
@ -462,7 +492,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
if (pullRequestHookTriggerHandler == null) {
initializeTriggerHandler();
}
pullRequestHookTriggerHandler.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
pullRequestHookTriggerHandler.handle(job, hook, buildInstructionFilterType, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
}
// executes when the Trigger receives a note request
@ -476,7 +506,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
if (noteHookTriggerHandler == null) {
initializeTriggerHandler();
}
noteHookTriggerHandler.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
noteHookTriggerHandler.handle(job, hook, buildInstructionFilterType, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
}
// executes when the Trigger receives a pipeline event
@ -484,7 +514,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
if (pipelineTriggerHandler == null) {
initializeTriggerHandler();
}
pipelineTriggerHandler.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
pipelineTriggerHandler.handle(job, hook, buildInstructionFilterType, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
}
private void initializeTriggerHandler() {
@ -540,6 +570,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
private transient final SequentialExecutionQueue queue = new SequentialExecutionQueue(Jenkins.MasterComputer.threadPoolForRemoting);
private boolean jobsMigrated = false;
private boolean jobsMigrated2 = false;
private boolean jobsMigrated3 = false;
private String GiteeApiToken;
private String giteeHostUrl = "";
private boolean ignoreCertificateErrors = false;

View File

@ -0,0 +1,16 @@
package com.gitee.jenkins.trigger.filter;
/**
* @author zhanggx
*/
public interface BuildInstructionFilter {
/**
* 是否触发构建
*
* @param body
* @return
*/
boolean isBuildAllow(String body);
}

View File

@ -0,0 +1,46 @@
package com.gitee.jenkins.trigger.filter;
/**
* @author zhanggx
*/
public enum BuildInstructionFilterType implements BuildInstructionFilter {
/**
* 无操作
*/
NONE("") {
@Override
public boolean isBuildAllow(String body) {
return true;
}
},
/**
* 包含 [ci-skip] 时跳过构建
*/
CI_SKIP("[ci-skip]") {
@Override
public boolean isBuildAllow(String body) {
return body == null ? true : !body.contains(getBody());
}
},
/**
* 包含 [ci-build] 时触发构建
*/
CI_BUILD("[ci-build]") {
@Override
public boolean isBuildAllow(String body) {
return body == null ? false : body.contains(getBody());
}
};
private String body;
BuildInstructionFilterType(String body) {
this.body = body;
}
public String getBody() {
return body;
}
}

View File

@ -5,6 +5,7 @@ import com.gitee.jenkins.cause.GiteeWebHookCause;
import com.gitee.jenkins.gitee.hook.model.WebHook;
import com.gitee.jenkins.trigger.exception.NoRevisionToBuildException;
import com.gitee.jenkins.trigger.filter.BranchFilter;
import com.gitee.jenkins.trigger.filter.BuildInstructionFilter;
import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter;
import com.gitee.jenkins.util.LoggerUtil;
import hudson.model.Action;
@ -34,8 +35,8 @@ public abstract class AbstractWebHookTriggerHandler<H extends WebHook> implement
protected PendingBuildsHandler pendingBuildsHandler = new PendingBuildsHandler();
@Override
public void handle(Job<?, ?> job, H hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
if (ciSkip && isCiSkip(hook)) {
public void handle(Job<?, ?> job, H hook, BuildInstructionFilter buildInstructionFilter, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
if (isCiSkip(hook, buildInstructionFilter)) {
LOGGER.log(Level.INFO, "Skipping due to ci-skip.");
return;
}
@ -57,7 +58,7 @@ public abstract class AbstractWebHookTriggerHandler<H extends WebHook> implement
protected abstract String getTriggerType();
protected abstract boolean isCiSkip(H hook);
protected abstract boolean isCiSkip(H hook, BuildInstructionFilter buildInstructionFilter);
protected abstract boolean isCommitSkip(Job<?, ?> job, H hook);
protected Action[] createActions(Job<?, ?> job, H hook) {

View File

@ -2,6 +2,7 @@ package com.gitee.jenkins.trigger.handler;
import com.gitee.jenkins.gitee.hook.model.WebHook;
import com.gitee.jenkins.trigger.filter.BranchFilter;
import com.gitee.jenkins.trigger.filter.BuildInstructionFilter;
import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter;
import hudson.model.Job;
@ -10,5 +11,6 @@ import hudson.model.Job;
*/
public interface WebHookTriggerHandler<H extends WebHook> {
void handle(Job<?, ?> job, H hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter);
void handle(Job<?, ?> job, H hook, BuildInstructionFilter buildInstructionFilter, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter);
}

View File

@ -2,6 +2,7 @@ package com.gitee.jenkins.trigger.handler.note;
import com.gitee.jenkins.gitee.hook.model.NoteHook;
import com.gitee.jenkins.trigger.filter.BranchFilter;
import com.gitee.jenkins.trigger.filter.BuildInstructionFilter;
import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter;
import hudson.model.Job;
@ -10,7 +11,7 @@ import hudson.model.Job;
*/
class NopNoteHookTriggerHandler implements NoteHookTriggerHandler {
@Override
public void handle(Job<?, ?> job, NoteHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
public void handle(Job<?, ?> job, NoteHook hook, BuildInstructionFilter buildInstructionFilter, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
// nothing to do
}
}

View File

@ -7,6 +7,7 @@ import com.gitee.jenkins.gitee.hook.model.*;
import com.gitee.jenkins.publisher.GiteeMessagePublisher;
import com.gitee.jenkins.trigger.exception.NoRevisionToBuildException;
import com.gitee.jenkins.trigger.filter.BranchFilter;
import com.gitee.jenkins.trigger.filter.BuildInstructionFilter;
import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter;
import com.gitee.jenkins.trigger.handler.AbstractWebHookTriggerHandler;
import hudson.model.Job;
@ -38,7 +39,7 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
}
@Override
public void handle(Job<?, ?> job, NoteHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
public void handle(Job<?, ?> job, NoteHook hook, BuildInstructionFilter buildInstructionFilter, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
if (isValidTrigger(hook)) {
// 若pr不可自动合并则评论至pr
PullRequestObjectAttributes objectAttributes = hook.getPullRequest();
@ -61,15 +62,13 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
}
super.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
super.handle(job, hook, buildInstructionFilter, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
}
}
@Override
protected boolean isCiSkip(NoteHook hook) {
return hook.getPullRequest() != null
&& hook.getPullRequest().getBody() != null
&& hook.getPullRequest().getBody().contains("[ci-skip]");
protected boolean isCiSkip(NoteHook hook, BuildInstructionFilter buildInstructionFilter) {
return hook.getPullRequest() == null ? false : !buildInstructionFilter.isBuildAllow(hook.getPullRequest().getBody());
}
@Override

View File

@ -2,6 +2,7 @@ package com.gitee.jenkins.trigger.handler.pipeline;
import com.gitee.jenkins.gitee.hook.model.PipelineHook;
import com.gitee.jenkins.trigger.filter.BranchFilter;
import com.gitee.jenkins.trigger.filter.BuildInstructionFilter;
import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter;
import hudson.model.Job;
@ -11,7 +12,7 @@ import hudson.model.Job;
class NopPipelineHookTriggerHandler implements PipelineHookTriggerHandler {
@Override
public void handle(Job<?, ?> job, PipelineHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
public void handle(Job<?, ?> job, PipelineHook hook, BuildInstructionFilter buildInstructionFilter, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
}
}

View File

@ -8,6 +8,7 @@ import com.gitee.jenkins.gitee.hook.model.PipelineEventObjectAttributes;
import com.gitee.jenkins.gitee.hook.model.PipelineHook;
import com.gitee.jenkins.trigger.exception.NoRevisionToBuildException;
import com.gitee.jenkins.trigger.filter.BranchFilter;
import com.gitee.jenkins.trigger.filter.BuildInstructionFilter;
import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter;
import com.gitee.jenkins.trigger.handler.AbstractWebHookTriggerHandler;
import com.gitee.jenkins.util.BuildUtil;
@ -44,7 +45,7 @@ class PipelineHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pipel
}
@Override
public void handle(Job<?, ?> job, PipelineHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
public void handle(Job<?, ?> job, PipelineHook hook, BuildInstructionFilter buildInstructionFilter, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
PipelineEventObjectAttributes objectAttributes = hook.getObjectAttributes();
try {
if (job instanceof AbstractProject<?, ?>) {
@ -58,7 +59,7 @@ class PipelineHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pipel
LOGGER.log(Level.WARNING, "Failed to communicate with gitee server to determine project id: " + e.getMessage(), e);
}
if (allowedStates.contains(objectAttributes.getStatus()) && !isLastAlreadyBuild(job,hook)) {
if (ciSkip && isCiSkip(hook)) {
if (isCiSkip(hook, buildInstructionFilter)) {
LOGGER.log(Level.INFO, "Skipping due to ci-skip.");
return;
}
@ -77,7 +78,7 @@ class PipelineHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pipel
}
@Override
protected boolean isCiSkip(PipelineHook hook) {
protected boolean isCiSkip(PipelineHook hook, BuildInstructionFilter buildInstructionFilter) {
//we don't get a commit message or suchlike that could contain ci-skip
return false;
}

View File

@ -2,6 +2,7 @@ package com.gitee.jenkins.trigger.handler.pull;
import com.gitee.jenkins.gitee.hook.model.PullRequestHook;
import com.gitee.jenkins.trigger.filter.BranchFilter;
import com.gitee.jenkins.trigger.filter.BuildInstructionFilter;
import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter;
import hudson.model.Job;
@ -10,7 +11,7 @@ import hudson.model.Job;
*/
class NopPullRequestHookTriggerHandler implements PullRequestHookTriggerHandler {
@Override
public void handle(Job<?, ?> job, PullRequestHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
public void handle(Job<?, ?> job, PullRequestHook hook, BuildInstructionFilter buildInstructionFilter, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
// nothing to do
}
}

View File

@ -9,6 +9,7 @@ import com.gitee.jenkins.gitee.hook.model.PullRequestHook;
import com.gitee.jenkins.publisher.GiteeMessagePublisher;
import com.gitee.jenkins.trigger.exception.NoRevisionToBuildException;
import com.gitee.jenkins.trigger.filter.BranchFilter;
import com.gitee.jenkins.trigger.filter.BuildInstructionFilter;
import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter;
import com.gitee.jenkins.trigger.handler.AbstractWebHookTriggerHandler;
import com.gitee.jenkins.util.BuildUtil;
@ -58,7 +59,7 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
}
@Override
public void handle(Job<?, ?> job, PullRequestHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
public void handle(Job<?, ?> job, PullRequestHook hook, BuildInstructionFilter buildInstructionFilter, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
PullRequestObjectAttributes objectAttributes = hook.getPullRequest();
try {
@ -93,7 +94,7 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
}
if (pullRequestLabelFilter.isPullRequestAllowed(labelsNames)) {
super.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
super.handle(job, hook, buildInstructionFilter, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
}
}
else {
@ -107,10 +108,8 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
}
@Override
protected boolean isCiSkip(PullRequestHook hook) {
return hook.getPullRequest() != null
&& hook.getPullRequest().getBody() != null
&& hook.getPullRequest().getBody().contains("[ci-skip]");
protected boolean isCiSkip(PullRequestHook hook, BuildInstructionFilter buildInstructionFilter) {
return hook.getPullRequest() == null ? false : !buildInstructionFilter.isBuildAllow(hook.getPullRequest().getBody());
}
@Override

View File

@ -2,6 +2,7 @@ package com.gitee.jenkins.trigger.handler.push;
import com.gitee.jenkins.gitee.hook.model.PushHook;
import com.gitee.jenkins.trigger.filter.BranchFilter;
import com.gitee.jenkins.trigger.filter.BuildInstructionFilter;
import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter;
import hudson.model.Job;
@ -10,7 +11,7 @@ import hudson.model.Job;
*/
class NopPushHookTriggerHandler implements PushHookTriggerHandler {
@Override
public void handle(Job<?, ?> job, PushHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
public void handle(Job<?, ?> job, PushHook hook, BuildInstructionFilter buildInstructionFilter, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
// nothing to do
}
}

View File

@ -6,6 +6,7 @@ import com.gitee.jenkins.gitee.hook.model.Commit;
import com.gitee.jenkins.gitee.hook.model.PushHook;
import com.gitee.jenkins.trigger.exception.NoRevisionToBuildException;
import com.gitee.jenkins.trigger.filter.BranchFilter;
import com.gitee.jenkins.trigger.filter.BuildInstructionFilter;
import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter;
import com.gitee.jenkins.trigger.handler.AbstractWebHookTriggerHandler;
import hudson.model.Job;
@ -31,19 +32,19 @@ class PushHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<PushHook>
private static final String NO_COMMIT = "0000000000000000000000000000000000000000";
@Override
public void handle(Job<?, ?> job, PushHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
public void handle(Job<?, ?> job, PushHook hook, BuildInstructionFilter buildInstructionFilter, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
if (isNoRemoveBranchPush(hook)) {
super.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
super.handle(job, hook, buildInstructionFilter, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
}
}
@Override
protected boolean isCiSkip(PushHook hook) {
protected boolean isCiSkip(PushHook hook, BuildInstructionFilter buildInstructionFilter) {
List<Commit> commits = hook.getCommits();
return commits != null &&
!commits.isEmpty() &&
commits.get(commits.size() - 1).getMessage() != null &&
commits.get(commits.size() - 1).getMessage().contains("[ci-skip]");
if (commits != null && !commits.isEmpty()) {
return !buildInstructionFilter.isBuildAllow(commits.get(commits.size() - 1).getMessage());
}
return false;
}
@Override

View File

@ -2,6 +2,7 @@ package com.gitee.jenkins.trigger.handler.push;
import com.gitee.jenkins.gitee.hook.model.PushHook;
import com.gitee.jenkins.trigger.filter.BranchFilter;
import com.gitee.jenkins.trigger.filter.BuildInstructionFilter;
import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter;
import hudson.model.Job;
@ -19,9 +20,9 @@ class PushHookTriggerHandlerList implements PushHookTriggerHandler {
}
@Override
public void handle(Job<?, ?> job, PushHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
public void handle(Job<?, ?> job, PushHook hook, BuildInstructionFilter buildInstructionFilter, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) {
for (PushHookTriggerHandler handler : handlers) {
handler.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
handler.handle(job, hook, buildInstructionFilter, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
}
}
}

View File

@ -40,9 +40,29 @@
</f:entry>
</table>
</f:entry>
<f:entry title="${%Enable.CI.Skip}" field="ciSkip" help="/plugin/gitee/help/help-ci-skip.html">
<f:checkbox default="true"/>
<f:entry title="${%Build.Instruction.Filter}">
<table>
<f:radioBlock name="buildInstructionFilterType"
value="NONE"
title="${%Build.Instruction.Filter.None}"
checked="${instance.buildInstructionFilterType == null || instance.buildInstructionFilterType == 'NONE'}"
inline="true"/>
<f:radioBlock name="buildInstructionFilterType"
value="CI_SKIP"
title="${%Build.Instruction.Filter.CiSkip}"
checked="${instance.buildInstructionFilterType == 'CI_SKIP'}"
inline="true"
help="/plugin/gitee/help/help-ci-skip.html"/>
<f:radioBlock name="buildInstructionFilterType"
value="CI_BUILD"
title="${%Build.Instruction.Filter.CiBuild}"
checked="${instance.buildInstructionFilterType == 'CI_BUILD'}"
inline="true"
help="/plugin/gitee/help/help-ci-build.html"/>
</table>
</f:entry>
<f:entry title="${%Enable.CI.SkipFroTestNotRequired}" field="ciSkipFroTestNotRequired" help="/plugin/gitee/help/help-ci-skip-test.html">
<f:checkbox default="true"/>
</f:entry>

View File

@ -3,6 +3,10 @@ Generate=Generate
Clear=Clear
Push=Push Events
Enable.CI.Skip=Enable [ci-skip]
Build.Instruction.Filter=Build instruction filter
Build.Instruction.Filter.None=None
Build.Instruction.Filter.CiSkip=[ci-skip] skip build
Build.Instruction.Filter.CiBuild=[ci-build] trigger build
Enable.CI.SkipFroTestNotRequired=Skip ci when test not required
Enabled.Gitee.Triggers=Enabled Gitee triggers
Approved.Pull.Request=Approved Pull Requests

View File

@ -4,6 +4,10 @@ Clear=\u6E05\u9664
Push=\u63A8\u9001\u4EE3\u7801
Enable.CI.Skip=\u652F\u6301 [ci-skip] \u6307\u4EE4\u8FC7\u6EE4\u6784\u5EFA
Enable.CI.SkipFroTestNotRequired=PR \u4E0D\u8981\u6C42\u5FC5\u987B\u6D4B\u8BD5\u65F6\u8FC7\u6EE4\u6784\u5EFA
Build.Instruction.Filter=\u6784\u5EFA\u6307\u4EE4\u8FC7\u6EE4
Build.Instruction.Filter.None=\u65E0
Build.Instruction.Filter.CiSkip=[ci-skip] \u6307\u4EE4\u8DF3\u8FC7\u6784\u5EFA
Build.Instruction.Filter.CiBuild=[ci-build] \u6307\u4EE4\u89E6\u53D1\u6784\u5EFA
Enabled.Gitee.Triggers=Gitee \u89E6\u53D1\u6784\u5EFA\u7B56\u7565
Approved.Pull.Request=\u5BA1\u67E5\u901A\u8FC7 Pull Requests
Tested.Pull.Request=\u6D4B\u8BD5\u901A\u8FC7 Pull Requests

View File

@ -0,0 +1,4 @@
<div>
For Push hook: build if the commit message contains <code>[ci-build]</code>.
For Pull Request hook: build if the pull request body contains <code>[ci-build]</code>.
</div>

View File

@ -0,0 +1,8 @@
<div>
<p>
代码推送触发: 若推送的最后一个提交的描述信息包含 <code>[ci-build]</code>,则触发构建。
</p>
<p>
PR 操作触发: 若 PR 的内容描述信息包含 <code>[ci-build]</code>,则触发构建。
</p>
</div>