Compare commits

..

38 Commits

Author SHA1 Message Date
Guixian Zhang b073013674 update README_zh_CN 2021-02-20 11:24:38 +08:00
Yashin f8da78cbf5 !13 评论触发人显示错误修复
Merge pull request !13 from silverballer/1.2.5
2021-02-20 10:25:29 +08:00
yashin 95fd15985a PR过滤不必要测试描述更改 2021-02-20 10:23:47 +08:00
Guixian Zhang 7141908ccb fix: trigger name error 2021-02-19 17:11:38 +08:00
Guixian Zhang 4b6f91c17a fix: comment trigger name error 2021-02-19 16:41:57 +08:00
yashin 3dde5acd67 [maven-release-plugin] prepare for next development iteration 2021-01-11 16:51:14 +08:00
yashin 3b77cd2c8b [maven-release-plugin] prepare release gitee-1.2.4 2021-01-11 16:50:57 +08:00
Yashin 7b53f0d613 !11 修复构建指令NPE
Merge pull request !11 from silverballer/1.2.4
2021-01-11 16:46:16 +08:00
Guixian Zhang 9fafeb7c5b fix: Build instruction NPE 2021-01-11 16:03:23 +08:00
yashin fce5b691b9 [maven-release-plugin] prepare for next development iteration 2021-01-07 17:55:30 +08:00
yashin 0588afd9fa [maven-release-plugin] prepare release gitee-1.2.3 2021-01-07 17:55:12 +08:00
Yashin 4eea07ed96 !10 忽略 Pull Request 冲突
Merge pull request !10 from silverballer/1.2.3
2021-01-07 17:48:19 +08:00
Guixian Zhang b4f954e3f1 Merge remote-tracking branch 'origin/1.2.3' into 1.2.3 2021-01-07 17:37:42 +08:00
Guixian Zhang e1da6195ce help update 2021-01-07 17:37:28 +08:00
silverballer 73ae3794a3 update README_zh_CN.md 2021-01-07 17:23:47 +08:00
Guixian Zhang 416f7ad38f feat: Add Ignore Pull Request conflicts option 2021-01-07 17:11:38 +08:00
yashin 9a8855fff2 [maven-release-plugin] prepare for next development iteration 2021-01-06 14:16:11 +08:00
yashin bf18ae350e [maven-release-plugin] prepare release gitee-1.2.2 2021-01-06 14:15:53 +08:00
Yashin 4c16f59c57 !9 修复流水线工程中止相同PR未完成构建错误
Merge pull request !9 from silverballer/1.2.1-bug-fix
2021-01-06 13:35:02 +08:00
Guixian Zhang d155c42a96 fix: workflow job abort error 2021-01-06 11:45:46 +08:00
yashin 879e5027b9 [maven-release-plugin] prepare for next development iteration 2021-01-04 18:09:30 +08:00
yashin 6082eb8255 [maven-release-plugin] prepare release gitee-1.2.1 2021-01-04 18:09:13 +08:00
Yashin a11c8b9201 !8 合并Github分支
Merge pull request !8 from silverballer/20201231-github-merge
2021-01-04 14:00:41 +08:00
Guixian Zhang fe8db03c7d GitHub merge 2021-01-04 13:30:50 +08:00
Guixian Zhang c6c5d50e41 GitHub merge 2020-12-31 18:27:15 +08:00
Guixian Zhang de24a2cce0 Merge remote-tracking branch 'origin/github' into zhangguixian-20201230-update
# Conflicts:
#	src/main/java/com/gitee/jenkins/trigger/handler/AbstractWebHookTriggerHandler.java
2020-12-31 18:21:47 +08:00
Yashin 12457b66d4 !7 增加commit评论触发开关、README修改、细节修改
Merge pull request !7 from silverballer/zhangguixian-20201230-update
2020-12-31 17:02:50 +08:00
yashin 68bc6bf280 [maven-release-plugin] prepare for next development iteration 2020-11-13 18:04:48 +08:00
yashin 65d027b406 [maven-release-plugin] prepare release gitee-1.1.15 2020-11-13 18:04:30 +08:00
yashin ed4ede6fad 增加json body 环境变量 2020-11-13 18:00:28 +08:00
yashin 51ff954947 [maven-release-plugin] prepare for next development iteration 2020-08-07 14:46:14 +08:00
yashin a1ecf59abe [maven-release-plugin] prepare release gitee-1.1.14 2020-08-07 14:45:53 +08:00
yashin 91d8b61f95 修复多仓库构建任务push触发构建失败 2020-08-07 14:41:56 +08:00
yashin 474e06c4bf [maven-release-plugin] prepare for next development iteration 2020-08-05 12:28:44 +08:00
yashin cf03c22092 [maven-release-plugin] prepare release gitee-1.1.13 2020-08-05 12:26:28 +08:00
yashin ea04e83e7a 修复git仓库与触发仓库不一致导致构建失败的问题 2020-08-05 12:01:46 +08:00
yashin d0a31c7261 [maven-release-plugin] prepare for next development iteration 2020-06-18 09:38:05 +08:00
yashin 25957fd1a3 [maven-release-plugin] prepare release gitee-1.1.12 2020-06-18 09:37:44 +08:00
22 changed files with 249 additions and 58 deletions

View File

@ -17,6 +17,7 @@
- [新建码云项目WebHook](#新建码云项目WebHook) - [新建码云项目WebHook](#新建码云项目WebHook)
- [测试推送触发构建](#测试推送触发构建) - [测试推送触发构建](#测试推送触发构建)
- [测试PR触发构建](#测试PR触发构建) - [测试PR触发构建](#测试PR触发构建)
- [使用脚本配置触发器](#使用脚本配置触发器)
- [环境变量](#环境变量) - [环境变量](#环境变量)
- [用户支持](#用户支持) - [用户支持](#用户支持)
- [参与贡献](#参与贡献) - [参与贡献](#参与贡献)
@ -135,11 +136,11 @@ Gitee Jenkins Plugin 是码云基于 [GitLab Plugin](https://github.com/jenkinsc
- `[ci-build] trigger build` commit message 或者 PR 说明包含 `[ci-build]` 时,触发构建。 - `[ci-build] trigger build` commit message 或者 PR 说明包含 `[ci-build]` 时,触发构建。
3. `Ignore last commit has build` 该选项可以跳过已经构建过的 Commit 版本。 3. `Ignore last commit has build` 该选项可以跳过已经构建过的 Commit 版本。
4. `Cancel incomplete build on same Pull Requests` 该选项在 PR 触发构建时,会判断是否存在相同 PR 且未完成的构建,有则取消未完成构建,再进行当前构建。 4. `Cancel incomplete build on same Pull Requests` 该选项在 PR 触发构建时,会判断是否存在相同 PR 且未完成的构建,有则取消未完成构建,再进行当前构建。
5. `Allowed branches` 可以配置允许构建的分支,目前支持分支名和正则表达式的方式进行过滤 5. `Ignore Pull Request conflicts` 该选项在 PR 触发构建时,会根据 PR 冲突情况选择是否进行构建
6. `Secret Token for Gitee WebHook` 该选项可以配置 WebHook 的密码,该密码需要与码云 WebHook配置的密码一致方可触发构建 6. `Allowed branches` 可以配置允许构建的分支,目前支持分支名和正则表达式的方式进行过滤
7. 注意:若 PR 状态为不可自动合并,则不触发构建。 7. `Secret Token for Gitee WebHook` 该选项可以配置 WebHook 的密码,该密码需要与码云 WebHook配置的密码一致方可触发构建。
![触发器配置](https://images.gitee.com/uploads/images/2020/1231/093554_e4c48be9_2102225.png "屏幕截图.png") 8. 注意:若 PR 状态为不可自动合并,则不触发构建。
![触发器配置](https://images.gitee.com/uploads/images/2021/0107/171932_e25c8359_2102225.png "屏幕截图.png")
### 构建后步骤配置 ### 构建后步骤配置
前往任务配置的构建后配置: Configure -> Post-build Actions 选项卡 前往任务配置的构建后配置: Configure -> Post-build Actions 选项卡
@ -172,6 +173,65 @@ Gitee Jenkins Plugin 是码云基于 [GitLab Plugin](https://github.com/jenkinsc
1. 码云的 WebHook 管理中选择勾选了 Pull Request 的 WebHook 点击测试,观察 Jenkins 任务的构建状态 1. 码云的 WebHook 管理中选择勾选了 Pull Request 的 WebHook 点击测试,观察 Jenkins 任务的构建状态
2. 在码云项目中新建一个Pull Request观察 Jenkins 任务的构建状态 2. 在码云项目中新建一个Pull Request观察 Jenkins 任务的构建状态
## 使用脚本配置触发器
```groovy
pipeline {
agent any
triggers {
gitee (
// 推送代码
triggerOnPush: true,
// 评论提交记录
triggerOnCommitComment: true,
// 新建 Pull Requests
triggerOnOpenPullRequest: true,
// 更新 Pull Requests "0":None "1":Source Branch updated "2":Target Branch updated "3":Both Source and Target Branch updated
triggerOnUpdatePullRequest: "1",
// 接受 Pull Requests
triggerOnAcceptedPullRequest: true,
// 关闭 Pull Requests
triggerOnClosedPullRequest: true,
// 审查通过 Pull Requests
triggerOnApprovedPullRequest: true,
// 测试通过 Pull Requests
triggerOnTestedPullRequest: true,
// 评论 Pull Requests
triggerOnNoteRequest: true,
// 评论内容的正则表达式
noteRegex: "build",
// 构建指令过滤 "NONE":无 "CI_SKIP":[ci-skip] 指令跳过构建 "CI_BUILD":[ci-build] 指令触发构建
buildInstructionFilterType: "NONE",
// PR 不要求必须测试时过滤构建
ciSkipFroTestNotRequired: false,
// 过滤已经构建的 Commit 版本
skipLastCommitHasBeenBuild: false,
// 取消相同 Pull Requests 未完成构建
cancelIncompleteBuildOnSamePullRequest: false,
// 允许触发构建的分支 "All":允许所有分支触发构建 "NameBasedFilter":根据分支名过滤 "RegexBasedFilter":根据正则表达式过滤分支
branchFilterType: "All",
// "NameBasedFilter" - 包括
includeBranchesSpec: "include",
// "NameBasedFilter" - 排除
excludeBranchesSpec: "exclude",
// "RegexBasedFilter" - 目标分支的正则表达式
targetBranchRegex: "regex",
// Gitee WebHook 密码
secretToken: "123456"
)
}
stages {
stage('Build') {
steps{
echo 'Hello world!'
}
}
}
}
```
# 环境变量 # 环境变量
目前支持环境变量见以下函数,其中不同的 WebHook 触发可能导致有些变量为空,具体请安装插件 [EnvInject Plugin](https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin),于构建中查看 Environment Variables 目前支持环境变量见以下函数,其中不同的 WebHook 触发可能导致有些变量为空,具体请安装插件 [EnvInject Plugin](https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin),于构建中查看 Environment Variables
@ -208,6 +268,9 @@ Gitee Jenkins Plugin 是码云基于 [GitLab Plugin](https://github.com/jenkinsc
variables.put("giteeTargetRepoHttpUrl", targetRepoHttpUrl); variables.put("giteeTargetRepoHttpUrl", targetRepoHttpUrl);
variables.put("giteeBefore", before); variables.put("giteeBefore", before);
variables.put("giteeAfter", after); variables.put("giteeAfter", after);
variables.put("giteeBeforeCommitSha", before);
variables.put("giteeAfterCommitSha", after);
variables.put("giteeRef", ref);
variables.put("ref", ref); variables.put("ref", ref);
variables.put("beforeSha", beforeSha); variables.put("beforeSha", beforeSha);
variables.put("isTag", isTag); variables.put("isTag", isTag);
@ -217,9 +280,12 @@ Gitee Jenkins Plugin 是码云基于 [GitLab Plugin](https://github.com/jenkinsc
variables.put("createdAt", createdAt); variables.put("createdAt", createdAt);
variables.put("finishedAt", finishedAt); variables.put("finishedAt", finishedAt);
variables.put("duration", buildDuration); variables.put("duration", buildDuration);
variables.put("jsonBody", jsonBody);
variables.put("noteBody", noteBody);
variables.putIfNotNull("giteeTriggerPhrase", triggerPhrase); variables.putIfNotNull("giteeTriggerPhrase", triggerPhrase);
return variables; return variables;
} }
``` ```
# 用户支持 # 用户支持

View File

@ -14,7 +14,7 @@
</properties> </properties>
<artifactId>gitee</artifactId> <artifactId>gitee</artifactId>
<version>1.1.12-SNAPSHOT</version> <version>1.2.5-SNAPSHOT</version>
<name>Gitee Plugin</name> <name>Gitee Plugin</name>
<description>This plugin integrates Gitee to Jenkins by faking a Gitee CI Server. This plugin allows Gitee to trigger builds in Jenkins when code is committed or pull requests are opened/updated. It can also send build status back to Gitee.</description> <description>This plugin integrates Gitee to Jenkins by faking a Gitee CI Server. This plugin allows Gitee to trigger builds in Jenkins when code is committed or pull requests are opened/updated. It can also send build status back to Gitee.</description>
<url>https://wiki.jenkins.io/display/JENKINS/Gitee+Plugin</url> <url>https://wiki.jenkins.io/display/JENKINS/Gitee+Plugin</url>

View File

@ -59,6 +59,8 @@ public final class CauseData {
private final String createdAt; private final String createdAt;
private final String finishedAt; private final String finishedAt;
private final String buildDuration; private final String buildDuration;
private final String jsonBody;
private final String noteBody;
private final boolean created; private final boolean created;
private final boolean deleted; private final boolean deleted;
@ -70,7 +72,7 @@ public final class CauseData {
String targetRepoSshUrl, String targetRepoHttpUrl, String triggeredByUser, String before, String after, String lastCommit, String targetRepoSshUrl, String targetRepoHttpUrl, String triggeredByUser, String before, String after, String lastCommit,
String targetProjectUrl, String triggerPhrase, String pullRequestState, String mergedByUser, String pullRequestAssignee, String targetProjectUrl, String triggerPhrase, String pullRequestState, String mergedByUser, String pullRequestAssignee,
String ref, String isTag, String sha, String beforeSha, String status, String stages, String createdAt, String finishedAt, String ref, String isTag, String sha, String beforeSha, String status, String stages, String createdAt, String finishedAt,
String buildDuration, String pathWithNamespace, boolean created, boolean deleted) { String buildDuration, String pathWithNamespace, boolean created, boolean deleted, String jsonBody, String noteBody) {
this.actionType = checkNotNull(actionType, "actionType must not be null."); this.actionType = checkNotNull(actionType, "actionType must not be null.");
this.sourceProjectId = checkNotNull(sourceProjectId, "sourceProjectId must not be null."); this.sourceProjectId = checkNotNull(sourceProjectId, "sourceProjectId must not be null.");
this.targetProjectId = checkNotNull(targetProjectId, "targetProjectId must not be null."); this.targetProjectId = checkNotNull(targetProjectId, "targetProjectId must not be null.");
@ -117,6 +119,8 @@ public final class CauseData {
this.pathWithNamespace = pathWithNamespace; this.pathWithNamespace = pathWithNamespace;
this.created = created; this.created = created;
this.deleted = deleted; this.deleted = deleted;
this.jsonBody = jsonBody;
this.noteBody = noteBody;
} }
public Map<String, String> getBuildVariables() { public Map<String, String> getBuildVariables() {
@ -162,6 +166,8 @@ public final class CauseData {
variables.put("createdAt", createdAt); variables.put("createdAt", createdAt);
variables.put("finishedAt", finishedAt); variables.put("finishedAt", finishedAt);
variables.put("duration", buildDuration); variables.put("duration", buildDuration);
variables.put("jsonBody", jsonBody);
variables.put("noteBody", noteBody);
variables.putIfNotNull("giteeTriggerPhrase", triggerPhrase); variables.putIfNotNull("giteeTriggerPhrase", triggerPhrase);
return variables; return variables;
} }
@ -298,6 +304,10 @@ public final class CauseData {
public String getBuildDuration() { return buildDuration; } public String getBuildDuration() { return buildDuration; }
public String getJsonBody() { return jsonBody; }
public String getNoteBody() { return noteBody; }
String getShortDescription() { String getShortDescription() {
return actionType.getShortDescription(this); return actionType.getShortDescription(this);
@ -386,6 +396,8 @@ public final class CauseData {
.append(pathWithNamespace, causeData.getPathWithNamespace()) .append(pathWithNamespace, causeData.getPathWithNamespace())
.append(created, causeData.getCreated()) .append(created, causeData.getCreated())
.append(deleted, causeData.getDeleted()) .append(deleted, causeData.getDeleted())
.append(jsonBody, causeData.getJsonBody())
.append(noteBody, causeData.getNoteBody())
.isEquals(); .isEquals();
} }
@ -435,6 +447,8 @@ public final class CauseData {
.append(pathWithNamespace) .append(pathWithNamespace)
.append(created) .append(created)
.append(deleted) .append(deleted)
.append(jsonBody)
.append(noteBody)
.toHashCode(); .toHashCode();
} }
@ -484,6 +498,8 @@ public final class CauseData {
.append("pathWithNamespace", pathWithNamespace) .append("pathWithNamespace", pathWithNamespace)
.append("created", created) .append("created", created)
.append("deleted", deleted) .append("deleted", deleted)
.append("jsonBody", jsonBody)
.append("noteBody", noteBody)
.toString(); .toString();
} }

View File

@ -13,6 +13,12 @@ public abstract class WebHook {
private Repository repository; private Repository repository;
private String objectKind; private String objectKind;
private String hookName; private String hookName;
private String jsonBody;
private User sender;
public String getJsonBody() { return this.jsonBody; }
public void setJsonBody(String json) { this.jsonBody = json; }
public String getHookName() { public String getHookName() {
return this.hookName; return this.hookName;
@ -38,6 +44,14 @@ public abstract class WebHook {
this.repository = repository; this.repository = repository;
} }
public User getSender() {
return sender;
}
public void setSender(User sender) {
this.sender = sender;
}
public String getWebHookDescription() { public String getWebHookDescription() {
return hookName; return hookName;
} }
@ -55,6 +69,7 @@ public abstract class WebHook {
.append(repository, webHook.repository) .append(repository, webHook.repository)
.append(objectKind, webHook.objectKind) .append(objectKind, webHook.objectKind)
.append(hookName, webHook.hookName) .append(hookName, webHook.hookName)
.append(sender, webHook.sender)
.isEquals(); .isEquals();
} }
@ -64,6 +79,7 @@ public abstract class WebHook {
.append(repository) .append(repository)
.append(hookName) .append(hookName)
.append(objectKind) .append(objectKind)
.append(sender)
.toHashCode(); .toHashCode();
} }
@ -73,6 +89,7 @@ public abstract class WebHook {
.append("repository", repository) .append("repository", repository)
.append("hookName", hookName) .append("hookName", hookName)
.append("objectKind", objectKind) .append("objectKind", objectKind)
.append("sender", sender)
.toString(); .toString();
} }
} }

View File

@ -76,7 +76,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
private boolean triggerOnNoteRequest = true; private boolean triggerOnNoteRequest = true;
private String noteRegex = ""; private String noteRegex = "";
private transient boolean ciSkip = true; private transient boolean ciSkip = true;
private BuildInstructionFilterType buildInstructionFilterType; private BuildInstructionFilterType buildInstructionFilterType = BuildInstructionFilterType.NONE;
private boolean skipWorkInProgressPullRequest; private boolean skipWorkInProgressPullRequest;
private boolean ciSkipFroTestNotRequired; private boolean ciSkipFroTestNotRequired;
private boolean skipLastCommitHasBeenBuild; private boolean skipLastCommitHasBeenBuild;
@ -95,6 +95,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
private String pendingBuildName; private String pendingBuildName;
private boolean cancelPendingBuildsOnUpdate; private boolean cancelPendingBuildsOnUpdate;
private boolean cancelIncompleteBuildOnSamePullRequest; private boolean cancelIncompleteBuildOnSamePullRequest;
private boolean ignorePullRequestConflicts;
private transient BranchFilter branchFilter; private transient BranchFilter branchFilter;
private transient PushHookTriggerHandler pushHookTriggerHandler; private transient PushHookTriggerHandler pushHookTriggerHandler;
@ -123,7 +124,8 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
String includeBranchesSpec, String excludeBranchesSpec, String targetBranchRegex, String includeBranchesSpec, String excludeBranchesSpec, String targetBranchRegex,
PullRequestLabelFilterConfig pullRequestLabelFilterConfig, String secretToken, boolean triggerOnPipelineEvent, PullRequestLabelFilterConfig pullRequestLabelFilterConfig, String secretToken, boolean triggerOnPipelineEvent,
boolean triggerOnApprovedPullRequest, String pendingBuildName, boolean cancelPendingBuildsOnUpdate, boolean triggerOnApprovedPullRequest, String pendingBuildName, boolean cancelPendingBuildsOnUpdate,
boolean cancelIncompleteBuildOnSamePullRequest) { boolean cancelIncompleteBuildOnSamePullRequest,
boolean ignorePullRequestConflicts) {
this.triggerOnPush = triggerOnPush; this.triggerOnPush = triggerOnPush;
this.triggerOnCommitComment = triggerOnCommitComment; this.triggerOnCommitComment = triggerOnCommitComment;
this.triggerOnOpenPullRequest = triggerOnOpenPullRequest; this.triggerOnOpenPullRequest = triggerOnOpenPullRequest;
@ -151,6 +153,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
this.pendingBuildName = pendingBuildName; this.pendingBuildName = pendingBuildName;
this.cancelPendingBuildsOnUpdate = cancelPendingBuildsOnUpdate; this.cancelPendingBuildsOnUpdate = cancelPendingBuildsOnUpdate;
this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest; this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest;
this.ignorePullRequestConflicts = ignorePullRequestConflicts;
initializeTriggerHandler(); initializeTriggerHandler();
initializeBranchFilter(); initializeBranchFilter();
@ -204,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();
} }
@ -334,6 +338,10 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
return cancelIncompleteBuildOnSamePullRequest; return cancelIncompleteBuildOnSamePullRequest;
} }
public boolean isIgnorePullRequestConflicts() {
return ignorePullRequestConflicts;
}
@DataBoundSetter @DataBoundSetter
public void setTriggerOnPush(boolean triggerOnPush) { public void setTriggerOnPush(boolean triggerOnPush) {
this.triggerOnPush = triggerOnPush; this.triggerOnPush = triggerOnPush;
@ -491,6 +499,11 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest; this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest;
} }
@DataBoundSetter
public void setIgnorePullRequestConflicts(boolean ignorePullRequestConflicts) {
this.ignorePullRequestConflicts = ignorePullRequestConflicts;
}
// executes when the Trigger receives a push request // executes when the Trigger receives a push request
public void onPost(final PushHook hook) { public void onPost(final PushHook hook) {
if (branchFilter == null) { if (branchFilter == null) {
@ -545,9 +558,10 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
pullRequestHookTriggerHandler = newPullRequestHookTriggerHandler(triggerOnOpenPullRequest, pullRequestHookTriggerHandler = newPullRequestHookTriggerHandler(triggerOnOpenPullRequest,
triggerOnUpdatePullRequest, triggerOnAcceptedPullRequest, triggerOnClosedPullRequest, triggerOnUpdatePullRequest, triggerOnAcceptedPullRequest, triggerOnClosedPullRequest,
skipWorkInProgressPullRequest, triggerOnApprovedPullRequest, triggerOnTestedPullRequest, cancelPendingBuildsOnUpdate, ciSkipFroTestNotRequired, skipWorkInProgressPullRequest, triggerOnApprovedPullRequest, triggerOnTestedPullRequest, cancelPendingBuildsOnUpdate, ciSkipFroTestNotRequired,
cancelIncompleteBuildOnSamePullRequest cancelIncompleteBuildOnSamePullRequest,
ignorePullRequestConflicts
); );
noteHookTriggerHandler = newNoteHookTriggerHandler(triggerOnCommitComment, triggerOnNoteRequest, noteRegex, ciSkipFroTestNotRequired, cancelIncompleteBuildOnSamePullRequest); noteHookTriggerHandler = newNoteHookTriggerHandler(triggerOnCommitComment, triggerOnNoteRequest, noteRegex, ciSkipFroTestNotRequired, cancelIncompleteBuildOnSamePullRequest, ignorePullRequestConflicts);
pushHookTriggerHandler = newPushHookTriggerHandler(triggerOnPush, skipWorkInProgressPullRequest); pushHookTriggerHandler = newPushHookTriggerHandler(triggerOnPush, skipWorkInProgressPullRequest);
pipelineTriggerHandler = newPipelineHookTriggerHandler(triggerOnPipelineEvent); pipelineTriggerHandler = newPipelineHookTriggerHandler(triggerOnPipelineEvent);
} }
@ -597,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

@ -8,9 +8,7 @@ import com.gitee.jenkins.trigger.filter.BranchFilter;
import com.gitee.jenkins.trigger.filter.BuildInstructionFilter; import com.gitee.jenkins.trigger.filter.BuildInstructionFilter;
import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter; import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter;
import com.gitee.jenkins.util.LoggerUtil; import com.gitee.jenkins.util.LoggerUtil;
import hudson.model.Action; import hudson.model.*;
import hudson.model.CauseAction;
import hudson.model.Job;
import hudson.plugins.git.GitSCM; import hudson.plugins.git.GitSCM;
import hudson.plugins.git.RevisionParameterAction; import hudson.plugins.git.RevisionParameterAction;
import hudson.scm.SCM; import hudson.scm.SCM;
@ -19,10 +17,14 @@ import jenkins.triggers.SCMTriggerItem;
import net.karneim.pojobuilder.GeneratePojoBuilder; import net.karneim.pojobuilder.GeneratePojoBuilder;
import org.eclipse.jgit.transport.RemoteConfig; import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.URIish;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import javax.servlet.ServletException;
import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -89,24 +91,19 @@ public abstract class AbstractWebHookTriggerHandler<H extends WebHook> implement
protected abstract BuildStatusUpdate retrieveBuildStatusUpdate(H hook); protected abstract BuildStatusUpdate retrieveBuildStatusUpdate(H hook);
protected URIish retrieveUrIish(WebHook hook, GitSCM gitSCM) { protected URIish retrieveUrIish(WebHook hook, GitSCM gitSCM) {
if (hook.getRepository() == null) { if (hook.getRepository() == null || gitSCM == null) {
return null; return null;
} }
try { try {
if (gitSCM == null) { Set<URIish> set = new HashSet<>();
return new URIish(hook.getRepository().getGitHttpUrl()); set.add(new URIish(hook.getRepository().getUrl()));
} set.add(new URIish(hook.getRepository().getGitHttpUrl()));
List<URIish> uris = new ArrayList<URIish>(); set.add(new URIish(hook.getRepository().getGitSshUrl()));
uris.add(new URIish(hook.getRepository().getUrl()));
uris.add(new URIish(hook.getRepository().getGitHttpUrl()));
uris.add(new URIish(hook.getRepository().getGitSshUrl()));
// uri 需与当前项目仓库个url一致避免触发多个构建 // uri 需与当前项目仓库个url一致避免触发多个构建
for (RemoteConfig remote : gitSCM.getRepositories()) { for (RemoteConfig remote : gitSCM.getRepositories()) {
for (URIish remoteURL : remote.getURIs()) { for (URIish remoteURL : remote.getURIs()) {
for (URIish uri : uris) { if (set.contains(remoteURL)) {
if (remoteURL.equals(uri)) { return remoteURL;
return uri;
}
} }
} }
} }
@ -148,6 +145,20 @@ public abstract class AbstractWebHookTriggerHandler<H extends WebHook> implement
return null; return null;
} }
protected void doStop(Run<?, ?> build) throws IOException, ServletException {
if (build.isBuilding()) {
if (build instanceof AbstractBuild) {
((AbstractBuild) build).doStop();
LOGGER.log(Level.WARNING, "Abort incomplete build");
} else if (build instanceof WorkflowRun) {
((WorkflowRun) build).doStop();
LOGGER.log(Level.WARNING, "Abort incomplete build");
} else {
LOGGER.log(Level.WARNING, "Unable to abort incomplete build, build type not found: " + build.getClass().getName());
}
}
}
public static class BuildStatusUpdate { public static class BuildStatusUpdate {
private final Integer projectId; private final Integer projectId;
private final String sha; private final String sha;

View File

@ -7,9 +7,9 @@ public final class NoteHookTriggerHandlerFactory {
private NoteHookTriggerHandlerFactory() {} private NoteHookTriggerHandlerFactory() {}
public static NoteHookTriggerHandler newNoteHookTriggerHandler(boolean triggerOnCommitComment, boolean triggerOnNoteRequest, String noteRegex, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest) { public static NoteHookTriggerHandler newNoteHookTriggerHandler(boolean triggerOnCommitComment, boolean triggerOnNoteRequest, String noteRegex, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest, boolean ignorePullRequestConflicts) {
if (triggerOnCommitComment || triggerOnNoteRequest) { if (triggerOnCommitComment || triggerOnNoteRequest) {
return new NoteHookTriggerHandlerImpl(triggerOnCommitComment, triggerOnNoteRequest, noteRegex, ciSkipFroTestNotRequired, cancelIncompleteBuildOnSamePullRequest); return new NoteHookTriggerHandlerImpl(triggerOnCommitComment, triggerOnNoteRequest, noteRegex, ciSkipFroTestNotRequired, cancelIncompleteBuildOnSamePullRequest, ignorePullRequestConflicts);
} else { } else {
return new NopNoteHookTriggerHandler(); return new NopNoteHookTriggerHandler();
} }

View File

@ -15,6 +15,7 @@ import hudson.model.*;
import hudson.plugins.git.GitSCM; import hudson.plugins.git.GitSCM;
import hudson.plugins.git.RevisionParameterAction; import hudson.plugins.git.RevisionParameterAction;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.eclipse.jgit.transport.URIish;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import java.io.IOException; import java.io.IOException;
@ -39,13 +40,15 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
private final String noteRegex; private final String noteRegex;
private final boolean ciSkipFroTestNotRequired; private final boolean ciSkipFroTestNotRequired;
private final boolean cancelIncompleteBuildOnSamePullRequest; private final boolean cancelIncompleteBuildOnSamePullRequest;
private boolean ignorePullRequestConflicts;
NoteHookTriggerHandlerImpl(boolean triggerOnCommitComment, boolean triggerOnNoteRequest, String noteRegex, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest) { NoteHookTriggerHandlerImpl(boolean triggerOnCommitComment, boolean triggerOnNoteRequest, String noteRegex, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest, boolean ignorePullRequestConflicts) {
this.triggerOnCommitComment = triggerOnCommitComment; this.triggerOnCommitComment = triggerOnCommitComment;
this.triggerOnNoteRequest = triggerOnNoteRequest; this.triggerOnNoteRequest = triggerOnNoteRequest;
this.noteRegex = noteRegex; this.noteRegex = noteRegex;
this.ciSkipFroTestNotRequired = ciSkipFroTestNotRequired; this.ciSkipFroTestNotRequired = ciSkipFroTestNotRequired;
this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest; this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest;
this.ignorePullRequestConflicts = ignorePullRequestConflicts;
} }
@Override @Override
@ -53,8 +56,12 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
if (isValidTrigger(hook)) { if (isValidTrigger(hook)) {
// 若pr不可自动合并则评论至pr // 若pr不可自动合并则评论至pr
PullRequestObjectAttributes objectAttributes = hook.getPullRequest(); PullRequestObjectAttributes objectAttributes = hook.getPullRequest();
if (objectAttributes != null && !objectAttributes.isMergeable()) { if (!ignorePullRequestConflicts && objectAttributes != null && !objectAttributes.isMergeable()) {
LOGGER.log(Level.INFO, "This pull request can not be merge"); LOGGER.log(Level.INFO, "This pull request can not be merge");
// fixme 无法获取 publisher
// java.lang.ClassCastException: org.jenkinsci.plugins.workflow.job.WorkflowJob cannot be cast to hudson.model.AbstractProject
// at com.gitee.jenkins.publisher.GiteeMessagePublisher.getFromJob(GiteeMessagePublisher.java:65)
// at com.gitee.jenkins.trigger.handler.note.NoteHookTriggerHandlerImpl.handle(NoteHookTriggerHandlerImpl.java:47)
GiteeMessagePublisher publisher = GiteeMessagePublisher.getFromJob(job); GiteeMessagePublisher publisher = GiteeMessagePublisher.getFromJob(job);
GiteeClient client = getClient(job); GiteeClient client = getClient(job);
if (publisher != null && client != null) { if (publisher != null && client != null) {
@ -78,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
@ -118,10 +128,7 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
&& causeData.getTargetRepoHttpUrl().equals(hook.getPullRequest().getTarget().getGitHttpUrl()) && causeData.getTargetRepoHttpUrl().equals(hook.getPullRequest().getTarget().getGitHttpUrl())
&& causeData.getRef().equals(hook.getPullRequest().getMergeReferenceName())) { && causeData.getRef().equals(hook.getPullRequest().getMergeReferenceName())) {
try { try {
if (build.isBuilding()) { doStop(build);
((AbstractBuild) build).doStop();
LOGGER.log(Level.WARNING, "Abort incomplete build");
}
} catch (ServletException | IOException e) { } catch (ServletException | IOException e) {
LOGGER.log(Level.WARNING, "Unable to abort incomplete build", e); LOGGER.log(Level.WARNING, "Unable to abort incomplete build", e);
} }
@ -163,7 +170,7 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
.withTargetNamespace(hook.getProject().getNamespace()) .withTargetNamespace(hook.getProject().getNamespace())
.withTargetRepoSshUrl(hook.getProject().getSshUrl()) .withTargetRepoSshUrl(hook.getProject().getSshUrl())
.withTargetRepoHttpUrl(hook.getProject().getGitHttpUrl()) .withTargetRepoHttpUrl(hook.getProject().getGitHttpUrl())
.withTriggeredByUser(hook.getComment().getUser().getName()) .withTriggeredByUser(hook.getSender().getName())
.withTriggerPhrase(hook.getComment().getBody()) .withTriggerPhrase(hook.getComment().getBody())
.withSha(hook.getComment().getCommitId()) .withSha(hook.getComment().getCommitId())
.withPathWithNamespace(hook.getProject().getPathWithNamespace()) .withPathWithNamespace(hook.getProject().getPathWithNamespace())
@ -194,7 +201,7 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
.withTargetNamespace(hook.getPullRequest().getTarget().getNamespace()) .withTargetNamespace(hook.getPullRequest().getTarget().getNamespace())
.withTargetRepoSshUrl(hook.getPullRequest().getTarget().getSshUrl()) .withTargetRepoSshUrl(hook.getPullRequest().getTarget().getSshUrl())
.withTargetRepoHttpUrl(hook.getPullRequest().getTarget().getGitHttpUrl()) .withTargetRepoHttpUrl(hook.getPullRequest().getTarget().getGitHttpUrl())
.withTriggeredByUser(hook.getPullRequest().getHead().getUser().getName()) .withTriggeredByUser(hook.getSender().getName())
.withLastCommit(hook.getPullRequest().getMergeCommitSha()) .withLastCommit(hook.getPullRequest().getMergeCommitSha())
.withSha(hook.getPullRequest().getMergeCommitSha()) .withSha(hook.getPullRequest().getMergeCommitSha())
.withAfter(hook.getPullRequest().getMergeCommitSha()) .withAfter(hook.getPullRequest().getMergeCommitSha())
@ -202,12 +209,23 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
.withTargetProjectUrl(hook.getPullRequest().getTarget().getUrl()) .withTargetProjectUrl(hook.getPullRequest().getTarget().getUrl())
.withTriggerPhrase(hook.getComment().getBody()) .withTriggerPhrase(hook.getComment().getBody())
.withPathWithNamespace(hook.getPullRequest().getBase().getRepo().getPathWithNamespace()) .withPathWithNamespace(hook.getPullRequest().getBase().getRepo().getPathWithNamespace())
.withJsonBody(hook.getJsonBody())
.withNoteBody(hook.getComment().getBody())
.build(); .build();
} }
@Override @Override
protected RevisionParameterAction createRevisionParameter(NoteHook hook, GitSCM gitSCM) throws NoRevisionToBuildException { protected RevisionParameterAction createRevisionParameter(NoteHook hook, GitSCM gitSCM) throws NoRevisionToBuildException {
return new RevisionParameterAction(retrieveRevisionToBuild(hook), retrieveUrIish(hook, gitSCM)); // 没有配置git源码管理
if (gitSCM == null) {
return new RevisionParameterAction(retrieveRevisionToBuild(hook));
}
URIish urIish = retrieveUrIish(hook, gitSCM);
// webhook与git源码管理仓库对不上
if (urIish == null) {
return new RevisionParameterAction(retrieveRevisionToBuild2(hook));
}
return new RevisionParameterAction(retrieveRevisionToBuild(hook), urIish);
} }
@Override @Override
@ -224,6 +242,13 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
if (hook.getPullRequest().getMergeCommitSha() != null) { if (hook.getPullRequest().getMergeCommitSha() != null) {
return hook.getPullRequest().getMergeCommitSha(); return hook.getPullRequest().getMergeCommitSha();
} }
}
return retrieveRevisionToBuild2(hook);
}
private String retrieveRevisionToBuild2(NoteHook hook) throws NoRevisionToBuildException {
if (hook.getPullRequest() != null) {
if (hook.getPullRequest().getMergeReferenceName() != null) { if (hook.getPullRequest().getMergeReferenceName() != null) {
return hook.getPullRequest().getMergeReferenceName(); return hook.getPullRequest().getMergeReferenceName();
} }

View File

@ -127,6 +127,7 @@ class PipelineHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pipel
.withCreatedAt(hook.getObjectAttributes().getCreatedAt()==null?"":hook.getObjectAttributes().getCreatedAt().toString()) .withCreatedAt(hook.getObjectAttributes().getCreatedAt()==null?"":hook.getObjectAttributes().getCreatedAt().toString())
.withFinishedAt(hook.getObjectAttributes().getFinishedAt()==null?"":hook.getObjectAttributes().getFinishedAt().toString()) .withFinishedAt(hook.getObjectAttributes().getFinishedAt()==null?"":hook.getObjectAttributes().getFinishedAt().toString())
.withBuildDuration(String.valueOf(hook.getObjectAttributes().getDuration())) .withBuildDuration(String.valueOf(hook.getObjectAttributes().getDuration()))
.withJsonBody(hook.getJsonBody())
.build(); .build();
} }

View File

@ -23,7 +23,8 @@ public final class PullRequestHookTriggerHandlerFactory {
boolean triggerOnTestedPullRequest, boolean triggerOnTestedPullRequest,
boolean cancelPendingBuildsOnUpdate, boolean cancelPendingBuildsOnUpdate,
boolean ciSkipFroTestNotRequired, boolean ciSkipFroTestNotRequired,
boolean cancelIncompleteBuildOnSamePullRequest) { boolean cancelIncompleteBuildOnSamePullRequest,
boolean ignorePullRequestConflicts) {
if (triggerOnOpenPullRequest if (triggerOnOpenPullRequest
|| !("0".equals(triggerOnUpdatePullRequest) || "false".equals(triggerOnUpdatePullRequest)) || !("0".equals(triggerOnUpdatePullRequest) || "false".equals(triggerOnUpdatePullRequest))
|| triggerOnAcceptedPullRequest || triggerOnAcceptedPullRequest
@ -48,7 +49,8 @@ public final class PullRequestHookTriggerHandlerFactory {
skipWorkInProgressPullRequest, skipWorkInProgressPullRequest,
cancelPendingBuildsOnUpdate, cancelPendingBuildsOnUpdate,
ciSkipFroTestNotRequired, ciSkipFroTestNotRequired,
cancelIncompleteBuildOnSamePullRequest); cancelIncompleteBuildOnSamePullRequest,
ignorePullRequestConflicts);
} else { } else {
return new NopPullRequestHookTriggerHandler(); return new NopPullRequestHookTriggerHandler();
} }

View File

@ -18,6 +18,7 @@ import hudson.model.*;
import hudson.plugins.git.GitSCM; import hudson.plugins.git.GitSCM;
import hudson.plugins.git.RevisionParameterAction; import hudson.plugins.git.RevisionParameterAction;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.eclipse.jgit.transport.URIish;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import java.io.IOException; import java.io.IOException;
@ -47,12 +48,13 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
private final Collection<ActionDesc> allowedActionDesces; private final Collection<ActionDesc> allowedActionDesces;
private final boolean cancelPendingBuildsOnUpdate; private final boolean cancelPendingBuildsOnUpdate;
private final boolean cancelIncompleteBuildOnSamePullRequest; private final boolean cancelIncompleteBuildOnSamePullRequest;
private boolean ignorePullRequestConflicts;
PullRequestHookTriggerHandlerImpl(Collection<State> allowedStates, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest) { PullRequestHookTriggerHandlerImpl(Collection<State> allowedStates, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest, boolean ignorePullRequestConflicts) {
this(allowedStates, EnumSet.allOf(Action.class), EnumSet.allOf(ActionDesc.class), skipWorkInProgressPullRequest, cancelPendingBuildsOnUpdate, ciSkipFroTestNotRequired, cancelIncompleteBuildOnSamePullRequest); this(allowedStates, EnumSet.allOf(Action.class), EnumSet.allOf(ActionDesc.class), skipWorkInProgressPullRequest, cancelPendingBuildsOnUpdate, ciSkipFroTestNotRequired, cancelIncompleteBuildOnSamePullRequest, ignorePullRequestConflicts);
} }
PullRequestHookTriggerHandlerImpl(Collection<State> allowedStates, Collection<Action> allowedActions, Collection<ActionDesc> allowedActionDesces, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest) { PullRequestHookTriggerHandlerImpl(Collection<State> allowedStates, Collection<Action> allowedActions, Collection<ActionDesc> allowedActionDesces, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest, boolean ignorePullRequestConflicts) {
this.allowedStates = allowedStates; this.allowedStates = allowedStates;
this.allowedActions = allowedActions; this.allowedActions = allowedActions;
this.allowedActionDesces = allowedActionDesces; this.allowedActionDesces = allowedActionDesces;
@ -60,6 +62,7 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
this.cancelPendingBuildsOnUpdate = cancelPendingBuildsOnUpdate; this.cancelPendingBuildsOnUpdate = cancelPendingBuildsOnUpdate;
this.ciSkipFroTestNotRequired = ciSkipFroTestNotRequired; this.ciSkipFroTestNotRequired = ciSkipFroTestNotRequired;
this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest; this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest;
this.ignorePullRequestConflicts = ignorePullRequestConflicts;
} }
@Override @Override
@ -78,7 +81,7 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
} }
// 若pr不可自动合并则评论至pr // 若pr不可自动合并则评论至pr
if (!objectAttributes.isMergeable()) { if (!ignorePullRequestConflicts && !objectAttributes.isMergeable()) {
LOGGER.log(Level.INFO, "This pull request can not be merge"); LOGGER.log(Level.INFO, "This pull request can not be merge");
GiteeMessagePublisher publisher = GiteeMessagePublisher.getFromJob(job); GiteeMessagePublisher publisher = GiteeMessagePublisher.getFromJob(job);
GiteeClient client = getClient(job); GiteeClient client = getClient(job);
@ -113,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
@ -173,10 +179,7 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
&& causeData.getTargetRepoHttpUrl().equals(hook.getPullRequest().getTarget().getGitHttpUrl()) && causeData.getTargetRepoHttpUrl().equals(hook.getPullRequest().getTarget().getGitHttpUrl())
&& causeData.getRef().equals(hook.getPullRequest().getMergeReferenceName())) { && causeData.getRef().equals(hook.getPullRequest().getMergeReferenceName())) {
try { try {
if (build.isBuilding()) { doStop(build);
((AbstractBuild) build).doStop();
LOGGER.log(Level.WARNING, "Abort incomplete build");
}
} catch (ServletException | IOException e) { } catch (ServletException | IOException e) {
LOGGER.log(Level.WARNING, "Unable to abort incomplete build", e); LOGGER.log(Level.WARNING, "Unable to abort incomplete build", e);
} }
@ -225,19 +228,29 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
.withTargetNamespace(hook.getPullRequest().getTarget().getNamespace()) .withTargetNamespace(hook.getPullRequest().getTarget().getNamespace())
.withTargetRepoSshUrl(hook.getPullRequest().getTarget().getSshUrl()) .withTargetRepoSshUrl(hook.getPullRequest().getTarget().getSshUrl())
.withTargetRepoHttpUrl(hook.getPullRequest().getTarget().getGitHttpUrl()) .withTargetRepoHttpUrl(hook.getPullRequest().getTarget().getGitHttpUrl())
.withTriggeredByUser(hook.getPullRequest().getHead().getUser().getName()) .withTriggeredByUser(hook.getSender().getName())
.withLastCommit(hook.getPullRequest().getMergeCommitSha()) .withLastCommit(hook.getPullRequest().getMergeCommitSha())
.withSha(hook.getPullRequest().getMergeCommitSha()) .withSha(hook.getPullRequest().getMergeCommitSha())
.withAfter(hook.getPullRequest().getMergeCommitSha()) .withAfter(hook.getPullRequest().getMergeCommitSha())
.withRef(hook.getPullRequest().getMergeReferenceName()) .withRef(hook.getPullRequest().getMergeReferenceName())
.withTargetProjectUrl(hook.getPullRequest().getTarget().getUrl()) .withTargetProjectUrl(hook.getPullRequest().getTarget().getUrl())
.withPathWithNamespace(hook.getRepo().getPathWithNamespace()) .withPathWithNamespace(hook.getRepo().getPathWithNamespace())
.withJsonBody(hook.getJsonBody())
.build(); .build();
} }
@Override @Override
protected RevisionParameterAction createRevisionParameter(PullRequestHook hook, GitSCM gitSCM) throws NoRevisionToBuildException { protected RevisionParameterAction createRevisionParameter(PullRequestHook hook, GitSCM gitSCM) throws NoRevisionToBuildException {
return new RevisionParameterAction(retrieveRevisionToBuild(hook), retrieveUrIish(hook, gitSCM)); // 没有配置git源码管理
if (gitSCM == null) {
return new RevisionParameterAction(retrieveRevisionToBuild(hook));
}
URIish urIish = retrieveUrIish(hook, gitSCM);
// webhook与git源码管理仓库对不上
if (urIish == null) {
return new RevisionParameterAction(retrieveRevisionToBuild2(hook));
}
return new RevisionParameterAction(retrieveRevisionToBuild(hook), urIish);
} }
@Override @Override
@ -254,6 +267,12 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
if (hook.getPullRequest().getMergeCommitSha() != null) { if (hook.getPullRequest().getMergeCommitSha() != null) {
return hook.getPullRequest().getMergeCommitSha(); return hook.getPullRequest().getMergeCommitSha();
} }
}
return retrieveRevisionToBuild2(hook);
}
private String retrieveRevisionToBuild2(PullRequestHook hook) throws NoRevisionToBuildException {
if (hook.getPullRequest() != null) {
if (hook.getPullRequest().getMergeReferenceName() != null) { if (hook.getPullRequest().getMergeReferenceName() != null) {
return hook.getPullRequest().getMergeReferenceName(); return hook.getPullRequest().getMergeReferenceName();
} }

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;
@ -92,7 +92,7 @@ class PushHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<PushHook>
.withTargetNamespace("") .withTargetNamespace("")
.withTargetRepoSshUrl("") .withTargetRepoSshUrl("")
.withTargetRepoHttpUrl("") .withTargetRepoHttpUrl("")
.withTriggeredByUser(retrievePushedBy(hook)) .withTriggeredByUser(hook.getSender().getName())
.withBefore(hook.getBefore()) .withBefore(hook.getBefore())
.withAfter(hook.getAfter()) .withAfter(hook.getAfter())
.withRef(hook.getRef()) .withRef(hook.getRef())
@ -101,6 +101,7 @@ class PushHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<PushHook>
.withCreated(hook.getCreated()) .withCreated(hook.getCreated())
.withDeleted(hook.getDeleted()) .withDeleted(hook.getDeleted())
.withTargetProjectUrl(hook.getProject().getUrl()) .withTargetProjectUrl(hook.getProject().getUrl())
.withJsonBody(hook.getJsonBody())
.build(); .build();
} }

View File

@ -30,6 +30,7 @@ public class NoteBuildAction extends BuildWebHookAction {
LOGGER.log(Level.FINE, "Note: {0}", toPrettyPrint(json)); LOGGER.log(Level.FINE, "Note: {0}", toPrettyPrint(json));
this.project = project; this.project = project;
this.noteHook = JsonUtil.read(json, NoteHook.class); this.noteHook = JsonUtil.read(json, NoteHook.class);
this.noteHook.setJsonBody(json);
this.secretToken = secretToken; this.secretToken = secretToken;
} }

View File

@ -31,6 +31,7 @@ public class PipelineBuildAction extends BuildWebHookAction {
LOGGER.log(Level.FINE, "Pipeline event: {0}", toPrettyPrint(json)); LOGGER.log(Level.FINE, "Pipeline event: {0}", toPrettyPrint(json));
this.project = project; this.project = project;
this.pipelineBuildHook = JsonUtil.read(json, PipelineHook.class); this.pipelineBuildHook = JsonUtil.read(json, PipelineHook.class);
this.pipelineBuildHook.setJsonBody(json);
this.secretToken = secretToken; this.secretToken = secretToken;
} }

View File

@ -30,6 +30,7 @@ public class PullRequestBuildAction extends BuildWebHookAction {
LOGGER.log(Level.FINE, "PullRequest: {0}", toPrettyPrint(json)); LOGGER.log(Level.FINE, "PullRequest: {0}", toPrettyPrint(json));
this.project = project; this.project = project;
this.pullRequestHook = JsonUtil.read(json, PullRequestHook.class); this.pullRequestHook = JsonUtil.read(json, PullRequestHook.class);
this.pullRequestHook.setJsonBody(json);
this.secretToken = secretToken; this.secretToken = secretToken;
} }

View File

@ -37,6 +37,7 @@ public class PushBuildAction extends BuildWebHookAction {
LOGGER.log(Level.FINE, "Push: {0}", toPrettyPrint(json)); LOGGER.log(Level.FINE, "Push: {0}", toPrettyPrint(json));
this.project = project; this.project = project;
this.pushHook = JsonUtil.read(json, PushHook.class); this.pushHook = JsonUtil.read(json, PushHook.class);
this.pushHook.setJsonBody(json);
this.secretToken = secretToken; this.secretToken = secretToken;
} }

View File

@ -80,6 +80,10 @@
<f:checkbox default="false"/> <f:checkbox default="false"/>
</f:entry> </f:entry>
<f:entry title="${%Ignore.Pull.Request.Conflicts}" field="ignorePullRequestConflicts" help="/plugin/gitee/help/help-ignore-pull-request-conflicts.html">
<f:checkbox default="false"/>
</f:entry>
<f:entry title="${%Allowed.branches}"> <f:entry title="${%Allowed.branches}">
<table> <table>
<!--<f:section title="">--> <!--<f:section title="">-->

View File

@ -39,6 +39,7 @@ Exclude=Exclude
Include=Include Include=Include
Ignore.Last.Commit.Has.Build=Ignore last commit has been build Ignore.Last.Commit.Has.Build=Ignore last commit has been build
Cancel.Same.Pull.Request.Incomplete.Build=Cancel incomplete build on same Pull Requests Cancel.Same.Pull.Request.Incomplete.Build=Cancel incomplete build on same Pull Requests
Ignore.Pull.Request.Conflicts=Ignore Pull Request conflicts
Comments=Comment Pull Requests Comments=Comment Pull Requests
Comment.Regex=Comment (regex) for triggering a build Comment.Regex=Comment (regex) for triggering a build
Retry.Text=Jenkins please retry a build Retry.Text=Jenkins please retry a build

View File

@ -39,6 +39,7 @@ Exclude=\u6392\u9664
Include=\u5305\u62EC Include=\u5305\u62EC
Ignore.Last.Commit.Has.Build=\u8FC7\u6EE4\u5DF2\u7ECF\u6784\u5EFA\u7684 Commit \u7248\u672C Ignore.Last.Commit.Has.Build=\u8FC7\u6EE4\u5DF2\u7ECF\u6784\u5EFA\u7684 Commit \u7248\u672C
Cancel.Same.Pull.Request.Incomplete.Build=\u53D6\u6D88\u76F8\u540C Pull Requests \u672A\u5B8C\u6210\u6784\u5EFA Cancel.Same.Pull.Request.Incomplete.Build=\u53D6\u6D88\u76F8\u540C Pull Requests \u672A\u5B8C\u6210\u6784\u5EFA
Ignore.Pull.Request.Conflicts=\u5FFD\u7565 Pull Request \u51B2\u7A81
Comments=\u8BC4\u8BBA Pull Requests Comments=\u8BC4\u8BBA Pull Requests
Comment.Regex=\u8BC4\u8BBA\u5185\u5BB9\u7684\u6B63\u5219\u8868\u8FBE\u5F0F Comment.Regex=\u8BC4\u8BBA\u5185\u5BB9\u7684\u6B63\u5219\u8868\u8FBE\u5F0F
Retry.Text=Jenkins please retry a build Retry.Text=Jenkins please retry a build

View File

@ -1,3 +1,3 @@
<div> <div>
码云 PR 表单中不勾选【必须测试】选项时,则过滤构建。 Gitee PR 表单中要求测试人数为0时,则过滤构建。
</div> </div>

View File

@ -0,0 +1,5 @@
<div>
If this option is selected,
the build will be triggered regardless of whether the Pull Request conflicts or not,
otherwise the Pull Request conflict will not trigger the build.
</div>

View File

@ -0,0 +1,3 @@
<div>
若勾选此选项,则无论 Pull Request 是否冲突都将触发构建,否则 Pull Request 冲突即不触发构建
</div>