增加过滤已经构建的commit版本

This commit is contained in:
yashin 2018-07-24 12:02:52 +08:00
parent 4a58541bfc
commit 7a2b9d5711
10 changed files with 48 additions and 15 deletions

View File

@ -69,7 +69,7 @@ Gitee Jenkins Plugin 是码云基于 [GitLab Plugin](https://github.com/jenkinsc
2. ``Kind`` 选择 ``Gitee API Token`` 2. ``Kind`` 选择 ``Gitee API Token``
3. ``Scope`` 选择你需要的范围 3. ``Scope`` 选择你需要的范围
4. ``Gitee API Token`` 输入你的码云私人令牌获取地址https://gitee.com/profile/personal_access_tokens 4. ``Gitee API Token`` 输入你的码云私人令牌获取地址https://gitee.com/profile/personal_access_tokens
5. ``ID``, ``Descripiton`` 中输入你要的 ID 和描述即可。 5. ``ID``, ``Descripiton`` 中输入你要的 ID 和描述即可。
5. ``Credentials`` 选择配置好的 Gitee APIV5 Token 5. ``Credentials`` 选择配置好的 Gitee APIV5 Token
6. 点击 ``Advanced`` ,可配置是否忽略 SSL 错误适您的Jenkins环境是否支持并可设置链接测超时时间适您的网络环境而定 6. 点击 ``Advanced`` ,可配置是否忽略 SSL 错误适您的Jenkins环境是否支持并可设置链接测超时时间适您的网络环境而定
7. 点击 ``Test Connection`` 测试链接是否成功,如失败请检查以上 356 步骤。 7. 点击 ``Test Connection`` 测试链接是否成功,如失败请检查以上 356 步骤。

View File

@ -80,6 +80,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
private String noteRegex = ""; private String noteRegex = "";
private boolean ciSkip = true; private boolean ciSkip = true;
private boolean skipWorkInProgressMergeRequest; private boolean skipWorkInProgressMergeRequest;
private boolean skipLastCommitHasBuild;
private boolean setBuildDescription = true; private boolean setBuildDescription = true;
private transient boolean addNoteOnMergeRequest; private transient boolean addNoteOnMergeRequest;
private transient boolean addCiMessage; private transient boolean addCiMessage;
@ -243,6 +244,10 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
return skipWorkInProgressMergeRequest; return skipWorkInProgressMergeRequest;
} }
public boolean isSkipLastCommitHasBuild() {
return skipLastCommitHasBuild;
}
public BranchFilterType getBranchFilterType() { public BranchFilterType getBranchFilterType() {
return branchFilterType; return branchFilterType;
} }
@ -325,6 +330,13 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
this.skipWorkInProgressMergeRequest = skipWorkInProgressMergeRequest; this.skipWorkInProgressMergeRequest = skipWorkInProgressMergeRequest;
} }
@DataBoundSetter
public void setSkipLastCommitHasBuild(boolean skipLastCommitHasBuild) {
this.skipLastCommitHasBuild = skipLastCommitHasBuild;
}
@DataBoundSetter @DataBoundSetter
public void setSetBuildDescription(boolean setBuildDescription) { public void setSetBuildDescription(boolean setBuildDescription) {
this.setBuildDescription = setBuildDescription; this.setBuildDescription = setBuildDescription;
@ -457,7 +469,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
private void initializeTriggerHandler() { private void initializeTriggerHandler() {
mergeRequestHookTriggerHandler = newMergeRequestHookTriggerHandler(triggerOnOpenMergeRequest, mergeRequestHookTriggerHandler = newMergeRequestHookTriggerHandler(triggerOnOpenMergeRequest,
triggerOnUpdateMergeRequest, triggerOnAcceptedMergeRequest, triggerOnClosedMergeRequest, triggerOnUpdateMergeRequest, triggerOnAcceptedMergeRequest, triggerOnClosedMergeRequest,
skipWorkInProgressMergeRequest, triggerOnApprovedMergeRequest, triggerOnTestedMergeRequest, cancelPendingBuildsOnUpdate); skipWorkInProgressMergeRequest, skipLastCommitHasBuild, triggerOnApprovedMergeRequest, triggerOnTestedMergeRequest, cancelPendingBuildsOnUpdate);
noteHookTriggerHandler = newNoteHookTriggerHandler(triggerOnNoteRequest, noteRegex); noteHookTriggerHandler = newNoteHookTriggerHandler(triggerOnNoteRequest, noteRegex);
pushHookTriggerHandler = newPushHookTriggerHandler(triggerOnPush, skipWorkInProgressMergeRequest); pushHookTriggerHandler = newPushHookTriggerHandler(triggerOnPush, skipWorkInProgressMergeRequest);
pipelineTriggerHandler = newPipelineHookTriggerHandler(triggerOnPipelineEvent); pipelineTriggerHandler = newPipelineHookTriggerHandler(triggerOnPipelineEvent);

View File

@ -20,6 +20,7 @@ public final class MergeRequestHookTriggerHandlerFactory {
boolean triggerOnAcceptedMergeRequest, boolean triggerOnAcceptedMergeRequest,
boolean triggerOnClosedMergeRequest, boolean triggerOnClosedMergeRequest,
boolean skipWorkInProgressMergeRequest, boolean skipWorkInProgressMergeRequest,
boolean skipLastCommitHasBuild,
boolean triggerOnApprovedMergeRequest, boolean triggerOnApprovedMergeRequest,
boolean triggerOnTestedMergeRequest, boolean triggerOnTestedMergeRequest,
boolean cancelPendingBuildsOnUpdate) { boolean cancelPendingBuildsOnUpdate) {
@ -44,6 +45,7 @@ public final class MergeRequestHookTriggerHandlerFactory {
triggerOnApprovedMergeRequest, triggerOnApprovedMergeRequest,
triggerOnTestedMergeRequest), triggerOnTestedMergeRequest),
skipWorkInProgressMergeRequest, skipWorkInProgressMergeRequest,
skipLastCommitHasBuild,
cancelPendingBuildsOnUpdate); cancelPendingBuildsOnUpdate);
} else { } else {
return new NopMergeRequestHookTriggerHandler(); return new NopMergeRequestHookTriggerHandler();

View File

@ -41,17 +41,19 @@ class MergeRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<M
private final Collection<State> allowedStates; private final Collection<State> allowedStates;
private final boolean skipWorkInProgressMergeRequest; private final boolean skipWorkInProgressMergeRequest;
private final boolean skipLastCommitHasBuild;
private final Collection<Action> allowedActions; private final Collection<Action> allowedActions;
private final boolean cancelPendingBuildsOnUpdate; private final boolean cancelPendingBuildsOnUpdate;
MergeRequestHookTriggerHandlerImpl(Collection<State> allowedStates, boolean skipWorkInProgressMergeRequest, boolean cancelPendingBuildsOnUpdate) { MergeRequestHookTriggerHandlerImpl(Collection<State> allowedStates, boolean skipWorkInProgressMergeRequest, boolean skipLastCommitHasBuild, boolean cancelPendingBuildsOnUpdate) {
this(allowedStates, EnumSet.allOf(Action.class), skipWorkInProgressMergeRequest, cancelPendingBuildsOnUpdate); this(allowedStates, EnumSet.allOf(Action.class), skipWorkInProgressMergeRequest, skipLastCommitHasBuild, cancelPendingBuildsOnUpdate);
} }
MergeRequestHookTriggerHandlerImpl(Collection<State> allowedStates, Collection<Action> allowedActions, boolean skipWorkInProgressMergeRequest, boolean cancelPendingBuildsOnUpdate) { MergeRequestHookTriggerHandlerImpl(Collection<State> allowedStates, Collection<Action> allowedActions, boolean skipWorkInProgressMergeRequest, boolean skipLastCommitHasBuild, boolean cancelPendingBuildsOnUpdate) {
this.allowedStates = allowedStates; this.allowedStates = allowedStates;
this.allowedActions = allowedActions; this.allowedActions = allowedActions;
this.skipWorkInProgressMergeRequest = skipWorkInProgressMergeRequest; this.skipWorkInProgressMergeRequest = skipWorkInProgressMergeRequest;
this.skipLastCommitHasBuild = skipLastCommitHasBuild;
this.cancelPendingBuildsOnUpdate = cancelPendingBuildsOnUpdate; this.cancelPendingBuildsOnUpdate = cancelPendingBuildsOnUpdate;
} }
@ -174,12 +176,12 @@ class MergeRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<M
} }
private boolean isLastCommitNotYetBuild(Job<?, ?> project, MergeRequestHook hook) { private boolean isLastCommitNotYetBuild(Job<?, ?> project, MergeRequestHook hook) {
MergeRequestObjectAttributes objectAttributes = hook.getPullRequest(); if (!skipLastCommitHasBuild) {
if (hook != null && hook.getAction() == Action.approved) {
LOGGER.log(Level.FINEST, "Skipping LastCommitNotYetBuild check for approve action");
return true; return true;
} }
MergeRequestObjectAttributes objectAttributes = hook.getPullRequest();
if (objectAttributes != null && objectAttributes.getMergeCommitSha() != null) { if (objectAttributes != null && objectAttributes.getMergeCommitSha() != null) {
Run<?, ?> mergeBuild = BuildUtil.getBuildBySHA1IncludingMergeBuilds(project, objectAttributes.getMergeCommitSha()); Run<?, ?> mergeBuild = BuildUtil.getBuildBySHA1IncludingMergeBuilds(project, objectAttributes.getMergeCommitSha());
if (mergeBuild != null && StringUtils.equals(getTargetBranchFromBuild(mergeBuild), objectAttributes.getTargetBranch())) { if (mergeBuild != null && StringUtils.equals(getTargetBranchFromBuild(mergeBuild), objectAttributes.getTargetBranch())) {
@ -200,12 +202,13 @@ class MergeRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<M
&& allowedActions.contains(hook.getAction()); && allowedActions.contains(hook.getAction());
} }
// Gitee 无此状态暂时屏蔽
private boolean isNotSkipWorkInProgressMergeRequest(MergeRequestObjectAttributes objectAttributes) { private boolean isNotSkipWorkInProgressMergeRequest(MergeRequestObjectAttributes objectAttributes) {
Boolean workInProgress = objectAttributes.getWorkInProgress(); // Boolean workInProgress = objectAttributes.getWorkInProgress();
if (skipWorkInProgressMergeRequest && workInProgress != null && workInProgress) { // if (skipWorkInProgressMergeRequest && workInProgress != null && workInProgress) {
LOGGER.log(Level.INFO, "Skip WIP Merge Request #{0} ({1})", toArray(objectAttributes.getNumber(), objectAttributes.getTitle())); // LOGGER.log(Level.INFO, "Skip WIP Merge Request #{0} ({1})", toArray(objectAttributes.getNumber(), objectAttributes.getTitle()));
return false; // return false;
} // }
return true; return true;
} }
} }

View File

@ -2,7 +2,7 @@ Gitee.connections=Gitee \u94FE\u63A5
Enable.authentication.end.point=\u5F00\u542F '/project' \u8DEF\u7531\u9A8C\u8BC1 Enable.authentication.end.point=\u5F00\u542F '/project' \u8DEF\u7531\u9A8C\u8BC1
Connection.name=\u94FE\u63A5\u540D Connection.name=\u94FE\u63A5\u540D
Gitee.host.URL=Gitee \u57DF\u540D URL Gitee.host.URL=Gitee \u57DF\u540D URL
Gitee.host.desc=Gitee \u57DF\u540D\u5B8C\u6574URL\u5730\u5740 (\u4F8B\u5982 http://gitee.com) Gitee.host.desc=Gitee \u57DF\u540D\u5B8C\u6574URL\u5730\u5740 (\u4F8B\u5982 https://gitee.com)
Credentials=\u8BC1\u4E66\u4EE4\u724C Credentials=\u8BC1\u4E66\u4EE4\u724C
Credentials.desc=Gitee API V5 \u7684\u79C1\u4EBA\u4EE4\u724C\uFF08\u83B7\u53D6\u5730\u5740 https://gitee.com/profile/personal_access_tokens\uFF09 Credentials.desc=Gitee API V5 \u7684\u79C1\u4EBA\u4EE4\u724C\uFF08\u83B7\u53D6\u5730\u5740 https://gitee.com/profile/personal_access_tokens\uFF09
Ignore.SSL.Certificate.Errors=\u5FFD\u7565 SSL \u8BC1\u4E66\u9519\u8BEF Ignore.SSL.Certificate.Errors=\u5FFD\u7565 SSL \u8BC1\u4E66\u9519\u8BEF

View File

@ -29,9 +29,16 @@
<f:entry title="${%Enable.CI.Skip}" field="ciSkip" help="/plugin/gitee/help/help-ci-skip.html"> <f:entry title="${%Enable.CI.Skip}" field="ciSkip" help="/plugin/gitee/help/help-ci-skip.html">
<f:checkbox default="true"/> <f:checkbox default="true"/>
</f:entry> </f:entry>
<f:entry title="${%Ignore.WIP.Merge.Requests}" field="skipWorkInProgressMergeRequest" help="/plugin/gitee/help/help-wip-pull-request.html">
<f:entry title="${%Ignore.Last.Commit.Has.Build}" field="skipLastCommitHasBuild" help="/plugin/gitee/help/help-skip-last-commit.html">
<f:checkbox default="false"/>
</f:entry>
<!--
<f:entry title="${%Ignore.WIP.Merge.Requests}" field="skipWorkInProgressMergeRequest" help="/plugin/gitee/help/help-skip-last-commit.html">
<f:checkbox default="true"/> <f:checkbox default="true"/>
</f:entry> </f:entry>
-->
<f:entry title="${%Allowed.branches}"> <f:entry title="${%Allowed.branches}">
<table> <table>
<!--<f:section title="">--> <!--<f:section title="">-->

View File

@ -31,3 +31,4 @@ Target.Branch.Regex=Target Branch Regex
Filter.merge.request.by.label=Filter merge request by label Filter.merge.request.by.label=Filter merge request by label
Exclude=Exclude Exclude=Exclude
Include=Include Include=Include
Ignore.Last.Commit.Has.Build=Ignore last commit has been build

View File

@ -31,3 +31,4 @@ Target.Branch.Regex=\u76EE\u6807\u5206\u652F\u7684\u6B63\u5219\u8868\u8FBE\u5F0F
Filter.merge.request.by.label=\u6839\u636E\u6807\u7B7E\u8FC7\u6EE4PR Filter.merge.request.by.label=\u6839\u636E\u6807\u7B7E\u8FC7\u6EE4PR
Exclude=\u6392\u9664 Exclude=\u6392\u9664
Include=\u5305\u62EC Include=\u5305\u62EC
Ignore.Last.Commit.Has.Build=\u8FC7\u6EE4\u5DF2\u7ECF\u6784\u5EFA\u7684 Commit \u7248\u672C

View File

@ -0,0 +1,4 @@
<div>
For Push event, Ignore last commit has been build.
For Pull Request, Ignore last merge commit has been build.
</div>

View File

@ -0,0 +1,3 @@
<div>
若推送或者 PR 的最后一个 Commit 已经构建过,则跳过重复触发构建。
</div>