Compare commits

..

No commits in common. "master" and "zhangguixian-20201230-update" have entirely different histories.

22 changed files with 58 additions and 249 deletions

View File

@ -17,7 +17,6 @@
- [新建码云项目WebHook](#新建码云项目WebHook)
- [测试推送触发构建](#测试推送触发构建)
- [测试PR触发构建](#测试PR触发构建)
- [使用脚本配置触发器](#使用脚本配置触发器)
- [环境变量](#环境变量)
- [用户支持](#用户支持)
- [参与贡献](#参与贡献)
@ -136,11 +135,11 @@ Gitee Jenkins Plugin 是码云基于 [GitLab Plugin](https://github.com/jenkinsc
- `[ci-build] trigger build` commit message 或者 PR 说明包含 `[ci-build]` 时,触发构建。
3. `Ignore last commit has build` 该选项可以跳过已经构建过的 Commit 版本。
4. `Cancel incomplete build on same Pull Requests` 该选项在 PR 触发构建时,会判断是否存在相同 PR 且未完成的构建,有则取消未完成构建,再进行当前构建。
5. `Ignore Pull Request conflicts` 该选项在 PR 触发构建时,会根据 PR 冲突情况选择是否进行构建
6. `Allowed branches` 可以配置允许构建的分支,目前支持分支名和正则表达式的方式进行过滤
7. `Secret Token for Gitee WebHook` 该选项可以配置 WebHook 的密码,该密码需要与码云 WebHook配置的密码一致方可触发构建。
8. 注意:若 PR 状态为不可自动合并,则不触发构建。
![触发器配置](https://images.gitee.com/uploads/images/2021/0107/171932_e25c8359_2102225.png "屏幕截图.png")
5. `Allowed branches` 可以配置允许构建的分支,目前支持分支名和正则表达式的方式进行过滤
6. `Secret Token for Gitee WebHook` 该选项可以配置 WebHook 的密码,该密码需要与码云 WebHook配置的密码一致方可触发构建
7. 注意:若 PR 状态为不可自动合并,则不触发构建。
![触发器配置](https://images.gitee.com/uploads/images/2020/1231/093554_e4c48be9_2102225.png "屏幕截图.png")
### 构建后步骤配置
前往任务配置的构建后配置: Configure -> Post-build Actions 选项卡
@ -173,65 +172,6 @@ Gitee Jenkins Plugin 是码云基于 [GitLab Plugin](https://github.com/jenkinsc
1. 码云的 WebHook 管理中选择勾选了 Pull Request 的 WebHook 点击测试,观察 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
@ -268,9 +208,6 @@ pipeline {
variables.put("giteeTargetRepoHttpUrl", targetRepoHttpUrl);
variables.put("giteeBefore", before);
variables.put("giteeAfter", after);
variables.put("giteeBeforeCommitSha", before);
variables.put("giteeAfterCommitSha", after);
variables.put("giteeRef", ref);
variables.put("ref", ref);
variables.put("beforeSha", beforeSha);
variables.put("isTag", isTag);
@ -280,12 +217,9 @@ pipeline {
variables.put("createdAt", createdAt);
variables.put("finishedAt", finishedAt);
variables.put("duration", buildDuration);
variables.put("jsonBody", jsonBody);
variables.put("noteBody", noteBody);
variables.putIfNotNull("giteeTriggerPhrase", triggerPhrase);
return variables;
}
```
# 用户支持

View File

@ -14,7 +14,7 @@
</properties>
<artifactId>gitee</artifactId>
<version>1.2.5-SNAPSHOT</version>
<version>1.1.12-SNAPSHOT</version>
<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>
<url>https://wiki.jenkins.io/display/JENKINS/Gitee+Plugin</url>

View File

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

View File

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

View File

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

View File

@ -8,7 +8,9 @@ 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.*;
import hudson.model.Action;
import hudson.model.CauseAction;
import hudson.model.Job;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.RevisionParameterAction;
import hudson.scm.SCM;
@ -17,14 +19,10 @@ import jenkins.triggers.SCMTriggerItem;
import net.karneim.pojobuilder.GeneratePojoBuilder;
import org.eclipse.jgit.transport.RemoteConfig;
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.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -91,19 +89,24 @@ public abstract class AbstractWebHookTriggerHandler<H extends WebHook> implement
protected abstract BuildStatusUpdate retrieveBuildStatusUpdate(H hook);
protected URIish retrieveUrIish(WebHook hook, GitSCM gitSCM) {
if (hook.getRepository() == null || gitSCM == null) {
if (hook.getRepository() == null) {
return null;
}
try {
Set<URIish> set = new HashSet<>();
set.add(new URIish(hook.getRepository().getUrl()));
set.add(new URIish(hook.getRepository().getGitHttpUrl()));
set.add(new URIish(hook.getRepository().getGitSshUrl()));
if (gitSCM == null) {
return new URIish(hook.getRepository().getGitHttpUrl());
}
List<URIish> uris = new ArrayList<URIish>();
uris.add(new URIish(hook.getRepository().getUrl()));
uris.add(new URIish(hook.getRepository().getGitHttpUrl()));
uris.add(new URIish(hook.getRepository().getGitSshUrl()));
// uri 需与当前项目仓库个url一致避免触发多个构建
for (RemoteConfig remote : gitSCM.getRepositories()) {
for (URIish remoteURL : remote.getURIs()) {
if (set.contains(remoteURL)) {
return remoteURL;
for (URIish uri : uris) {
if (remoteURL.equals(uri)) {
return uri;
}
}
}
}
@ -145,20 +148,6 @@ public abstract class AbstractWebHookTriggerHandler<H extends WebHook> implement
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 {
private final Integer projectId;
private final String sha;

View File

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

View File

@ -15,7 +15,6 @@ import hudson.model.*;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.RevisionParameterAction;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jgit.transport.URIish;
import javax.servlet.ServletException;
import java.io.IOException;
@ -40,15 +39,13 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
private final String noteRegex;
private final boolean ciSkipFroTestNotRequired;
private final boolean cancelIncompleteBuildOnSamePullRequest;
private boolean ignorePullRequestConflicts;
NoteHookTriggerHandlerImpl(boolean triggerOnCommitComment, boolean triggerOnNoteRequest, String noteRegex, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest, boolean ignorePullRequestConflicts) {
NoteHookTriggerHandlerImpl(boolean triggerOnCommitComment, boolean triggerOnNoteRequest, String noteRegex, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest) {
this.triggerOnCommitComment = triggerOnCommitComment;
this.triggerOnNoteRequest = triggerOnNoteRequest;
this.noteRegex = noteRegex;
this.ciSkipFroTestNotRequired = ciSkipFroTestNotRequired;
this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest;
this.ignorePullRequestConflicts = ignorePullRequestConflicts;
}
@Override
@ -56,12 +53,8 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
if (isValidTrigger(hook)) {
// 若pr不可自动合并则评论至pr
PullRequestObjectAttributes objectAttributes = hook.getPullRequest();
if (!ignorePullRequestConflicts && objectAttributes != null && !objectAttributes.isMergeable()) {
if (objectAttributes != null && !objectAttributes.isMergeable()) {
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);
GiteeClient client = getClient(job);
if (publisher != null && client != null) {
@ -85,10 +78,7 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
@Override
protected boolean isCiSkip(NoteHook hook, BuildInstructionFilter buildInstructionFilter) {
if (buildInstructionFilter != null && hook.getPullRequest() != null) {
return !buildInstructionFilter.isBuildAllow(hook.getPullRequest().getBody());
}
return false;
return hook.getPullRequest() == null ? false : !buildInstructionFilter.isBuildAllow(hook.getPullRequest().getBody());
}
@Override
@ -128,7 +118,10 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
&& causeData.getTargetRepoHttpUrl().equals(hook.getPullRequest().getTarget().getGitHttpUrl())
&& causeData.getRef().equals(hook.getPullRequest().getMergeReferenceName())) {
try {
doStop(build);
if (build.isBuilding()) {
((AbstractBuild) build).doStop();
LOGGER.log(Level.WARNING, "Abort incomplete build");
}
} catch (ServletException | IOException e) {
LOGGER.log(Level.WARNING, "Unable to abort incomplete build", e);
}
@ -170,7 +163,7 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
.withTargetNamespace(hook.getProject().getNamespace())
.withTargetRepoSshUrl(hook.getProject().getSshUrl())
.withTargetRepoHttpUrl(hook.getProject().getGitHttpUrl())
.withTriggeredByUser(hook.getSender().getName())
.withTriggeredByUser(hook.getComment().getUser().getName())
.withTriggerPhrase(hook.getComment().getBody())
.withSha(hook.getComment().getCommitId())
.withPathWithNamespace(hook.getProject().getPathWithNamespace())
@ -201,7 +194,7 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
.withTargetNamespace(hook.getPullRequest().getTarget().getNamespace())
.withTargetRepoSshUrl(hook.getPullRequest().getTarget().getSshUrl())
.withTargetRepoHttpUrl(hook.getPullRequest().getTarget().getGitHttpUrl())
.withTriggeredByUser(hook.getSender().getName())
.withTriggeredByUser(hook.getPullRequest().getHead().getUser().getName())
.withLastCommit(hook.getPullRequest().getMergeCommitSha())
.withSha(hook.getPullRequest().getMergeCommitSha())
.withAfter(hook.getPullRequest().getMergeCommitSha())
@ -209,23 +202,12 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
.withTargetProjectUrl(hook.getPullRequest().getTarget().getUrl())
.withTriggerPhrase(hook.getComment().getBody())
.withPathWithNamespace(hook.getPullRequest().getBase().getRepo().getPathWithNamespace())
.withJsonBody(hook.getJsonBody())
.withNoteBody(hook.getComment().getBody())
.build();
}
@Override
protected RevisionParameterAction createRevisionParameter(NoteHook hook, GitSCM gitSCM) throws NoRevisionToBuildException {
// 没有配置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);
return new RevisionParameterAction(retrieveRevisionToBuild(hook), retrieveUrIish(hook, gitSCM));
}
@Override
@ -242,13 +224,6 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
if (hook.getPullRequest().getMergeCommitSha() != null) {
return hook.getPullRequest().getMergeCommitSha();
}
}
return retrieveRevisionToBuild2(hook);
}
private String retrieveRevisionToBuild2(NoteHook hook) throws NoRevisionToBuildException {
if (hook.getPullRequest() != null) {
if (hook.getPullRequest().getMergeReferenceName() != null) {
return hook.getPullRequest().getMergeReferenceName();
}

View File

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

View File

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

View File

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

View File

@ -41,7 +41,7 @@ class PushHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<PushHook>
@Override
protected boolean isCiSkip(PushHook hook, BuildInstructionFilter buildInstructionFilter) {
List<Commit> commits = hook.getCommits();
if (buildInstructionFilter!= null && commits != null && !commits.isEmpty()) {
if (commits != null && !commits.isEmpty()) {
return !buildInstructionFilter.isBuildAllow(commits.get(commits.size() - 1).getMessage());
}
return false;
@ -92,7 +92,7 @@ class PushHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<PushHook>
.withTargetNamespace("")
.withTargetRepoSshUrl("")
.withTargetRepoHttpUrl("")
.withTriggeredByUser(hook.getSender().getName())
.withTriggeredByUser(retrievePushedBy(hook))
.withBefore(hook.getBefore())
.withAfter(hook.getAfter())
.withRef(hook.getRef())
@ -101,7 +101,6 @@ class PushHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<PushHook>
.withCreated(hook.getCreated())
.withDeleted(hook.getDeleted())
.withTargetProjectUrl(hook.getProject().getUrl())
.withJsonBody(hook.getJsonBody())
.build();
}

View File

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

View File

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

View File

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

View File

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

View File

@ -80,10 +80,6 @@
<f:checkbox default="false"/>
</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}">
<table>
<!--<f:section title="">-->

View File

@ -39,7 +39,6 @@ Exclude=Exclude
Include=Include
Ignore.Last.Commit.Has.Build=Ignore last commit has been build
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
Comment.Regex=Comment (regex) for triggering a build
Retry.Text=Jenkins please retry a build

View File

@ -39,7 +39,6 @@ Exclude=\u6392\u9664
Include=\u5305\u62EC
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
Ignore.Pull.Request.Conflicts=\u5FFD\u7565 Pull Request \u51B2\u7A81
Comments=\u8BC4\u8BBA Pull Requests
Comment.Regex=\u8BC4\u8BBA\u5185\u5BB9\u7684\u6B63\u5219\u8868\u8FBE\u5F0F
Retry.Text=Jenkins please retry a build

View File

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

View File

@ -1,5 +0,0 @@
<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

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