diff --git a/src/main/java/org/jenkinsci/plugins/gitlab/GitLabEnvironmentContributor.java b/src/main/java/org/jenkinsci/plugins/gitlab/GitLabEnvironmentContributor.java index 657d16e..fa2581d 100644 --- a/src/main/java/org/jenkinsci/plugins/gitlab/GitLabEnvironmentContributor.java +++ b/src/main/java/org/jenkinsci/plugins/gitlab/GitLabEnvironmentContributor.java @@ -31,6 +31,7 @@ public void buildEnvironmentFor(@Nonnull Run r, @Nonnull EnvVars envs, variables.put("gitlabSourceProjectId", cause.getSourceProjectId()+""); variables.put("gitlabTargetProjectId", cause.getTargetProjectId()+""); variables.put("gitlabLastCommitId", cause.getLastCommitId()); + variables.put("gitlabNote", cause.getNote()); envs.overrideAll(variables); } } diff --git a/src/main/java/org/jenkinsci/plugins/gitlab/GitlabBuildTrigger.java b/src/main/java/org/jenkinsci/plugins/gitlab/GitlabBuildTrigger.java index 95e5d91..3c1ddca 100755 --- a/src/main/java/org/jenkinsci/plugins/gitlab/GitlabBuildTrigger.java +++ b/src/main/java/org/jenkinsci/plugins/gitlab/GitlabBuildTrigger.java @@ -88,6 +88,7 @@ public QueueTaskFuture startJob(GitlabCause cause) { values.put("gitlabTargetBranch", new StringParameterValue("gitlabTargetBranch", cause.getTargetBranch())); values.put("gitlabTitle", new StringParameterValue("gitlabTitle", cause.getTitle())); values.put("gitlabDescription", new StringParameterValue("gitlabDescription", cause.getDescription())); + values.put("gitlabNote", new StringParameterValue("gitlabNote", cause.getNote())); for (Map.Entry entry : cause.getCustomParameters().entrySet()) { values.put(entry.getKey(), new StringParameterValue(entry.getKey(), entry.getValue())); } @@ -240,7 +241,7 @@ public boolean isApplicable(Item item) { @Override public String getDisplayName() { - return "Gitlab Merge Requests Builder"; + return "JD Gitlab Merge Requests Builder(V1.0)"; } @Override diff --git a/src/main/java/org/jenkinsci/plugins/gitlab/GitlabBuilds.java b/src/main/java/org/jenkinsci/plugins/gitlab/GitlabBuilds.java index 1a0d1b5..44ed89d 100755 --- a/src/main/java/org/jenkinsci/plugins/gitlab/GitlabBuilds.java +++ b/src/main/java/org/jenkinsci/plugins/gitlab/GitlabBuilds.java @@ -39,6 +39,7 @@ public GitlabBuilds(GitlabBuildTrigger trigger, GitlabRepository repository) { public String build(GitlabCause cause, Map customParameters, GitlabProject project, GitlabMergeRequest mergeRequest) throws IOException { boolean shouldRun = true; + boolean shouldRunCauseByNote = false; GitlabAPI api = trigger.getBuilder().getGitlab().get(); String triggerComment = trigger.getTriggerComment(); GitlabNote lastNote = getLastNote(mergeRequest, api); @@ -55,9 +56,11 @@ public String build(GitlabCause cause, Map customParameters, Git shouldRun = false; } - if (lastNote != null && lastNote.getBody().equals(triggerComment)) { + if (lastNote != null && lastNote.getBody().startsWith(triggerComment)) { LOGGER.info("Trigger comment found"); shouldRun = true; + shouldRunCauseByNote = true; + cause.setNote(lastNote.getBody().replace(triggerComment, "").trim()); } if (shouldRun) { @@ -78,7 +81,7 @@ public String build(GitlabCause cause, Map customParameters, Git } if (shouldRun) { - if (isWorkInProgress(mergeRequest.getTitle())) { + if (!shouldRunCauseByNote && isWorkInProgress(mergeRequest.getTitle())) { shouldRun = false; } } diff --git a/src/main/java/org/jenkinsci/plugins/gitlab/GitlabCause.java b/src/main/java/org/jenkinsci/plugins/gitlab/GitlabCause.java index ac5e2fb..6f864e4 100755 --- a/src/main/java/org/jenkinsci/plugins/gitlab/GitlabCause.java +++ b/src/main/java/org/jenkinsci/plugins/gitlab/GitlabCause.java @@ -17,6 +17,7 @@ public class GitlabCause extends Cause { private final Integer sourceProjectId; private final Integer targetProjectId; private final String lastCommitId; + private String note; public GitlabCause(Integer mergeRequestId, Integer mergeRequestIid, @@ -94,7 +95,15 @@ public Integer getTargetProjectId() { return targetProjectId; } - public String getLastCommitId() { + public String getLastCommitId() { return lastCommitId; } + + public void setNote(String note) { + this.note = note; + } + + public String getNote() { + return note; + } } diff --git a/src/main/java/org/jenkinsci/plugins/gitlab/GitlabMergeRequestWrapper.java b/src/main/java/org/jenkinsci/plugins/gitlab/GitlabMergeRequestWrapper.java index ba4a0b1..e341e2b 100755 --- a/src/main/java/org/jenkinsci/plugins/gitlab/GitlabMergeRequestWrapper.java +++ b/src/main/java/org/jenkinsci/plugins/gitlab/GitlabMergeRequestWrapper.java @@ -76,15 +76,16 @@ public void check(GitlabMergeRequest gitlabMergeRequest) { sourceBranch = gitlabMergeRequest.getSourceBranch(); } + // force to get new title. + title = gitlabMergeRequest.getTitle(); if (title == null || title.trim().isEmpty()) { - title = gitlabMergeRequest.getTitle(); - +// title = gitlabMergeRequest.getTitle(); if (title == null) { title = ""; } } + description = gitlabMergeRequest.getDescription(); if (description == null || description.trim().isEmpty()) { - description = gitlabMergeRequest.getDescription(); - +// description = gitlabMergeRequest.getDescription(); if (description == null) { description = ""; } }