增加json body 环境变量
This commit is contained in:
parent
51ff954947
commit
ed4ede6fad
|
@ -202,6 +202,9 @@ Gitee Jenkins Plugin 是码云基于 [GitLab Plugin](https://github.com/jenkinsc
|
|||
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);
|
||||
|
@ -211,9 +214,12 @@ Gitee Jenkins Plugin 是码云基于 [GitLab Plugin](https://github.com/jenkinsc
|
|||
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;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
# 用户支持
|
||||
|
|
|
@ -59,6 +59,8 @@ 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;
|
||||
|
||||
|
@ -70,7 +72,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 buildDuration, String pathWithNamespace, boolean created, boolean deleted, String jsonBody, String noteBody) {
|
||||
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.");
|
||||
|
@ -117,6 +119,8 @@ public final class CauseData {
|
|||
this.pathWithNamespace = pathWithNamespace;
|
||||
this.created = created;
|
||||
this.deleted = deleted;
|
||||
this.jsonBody = jsonBody;
|
||||
this.noteBody = noteBody;
|
||||
}
|
||||
|
||||
public Map<String, String> getBuildVariables() {
|
||||
|
@ -162,6 +166,8 @@ 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;
|
||||
}
|
||||
|
@ -298,6 +304,10 @@ 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);
|
||||
|
@ -386,6 +396,8 @@ 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();
|
||||
}
|
||||
|
||||
|
@ -435,6 +447,8 @@ public final class CauseData {
|
|||
.append(pathWithNamespace)
|
||||
.append(created)
|
||||
.append(deleted)
|
||||
.append(jsonBody)
|
||||
.append(noteBody)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
|
@ -484,6 +498,8 @@ public final class CauseData {
|
|||
.append("pathWithNamespace", pathWithNamespace)
|
||||
.append("created", created)
|
||||
.append("deleted", deleted)
|
||||
.append("jsonBody", jsonBody)
|
||||
.append("noteBody", noteBody)
|
||||
.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,11 @@ public abstract class WebHook {
|
|||
private Repository repository;
|
||||
private String objectKind;
|
||||
private String hookName;
|
||||
private String jsonBody;
|
||||
|
||||
public String getJsonBody() { return this.jsonBody; }
|
||||
|
||||
public void setJsonBody(String json) { this.jsonBody = json; }
|
||||
|
||||
public String getHookName() {
|
||||
return this.hookName;
|
||||
|
|
|
@ -44,6 +44,10 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
|
|||
PullRequestObjectAttributes objectAttributes = hook.getPullRequest();
|
||||
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) {
|
||||
|
@ -120,6 +124,8 @@ 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -126,6 +126,7 @@ 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -184,6 +184,7 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
|
|||
.withRef(hook.getPullRequest().getMergeReferenceName())
|
||||
.withTargetProjectUrl(hook.getPullRequest().getTarget().getUrl())
|
||||
.withPathWithNamespace(hook.getRepo().getPathWithNamespace())
|
||||
.withJsonBody(hook.getJsonBody())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@ class PushHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<PushHook>
|
|||
.withCreated(hook.getCreated())
|
||||
.withDeleted(hook.getDeleted())
|
||||
.withTargetProjectUrl(hook.getProject().getUrl())
|
||||
.withJsonBody(hook.getJsonBody())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue