Skip to content

Commit

Permalink
fix: get project/job url error when not config root url (#252)
Browse files Browse the repository at this point in the history
Signed-off-by: BobDu <[email protected]>
  • Loading branch information
BobDu authored Feb 24, 2024
1 parent 4736543 commit 804897f
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/main/java/io/jenkins/plugins/DingTalkRunListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public class DingTalkRunListener extends RunListener<Run<?, ?>> {

private final DingTalkServiceImpl service = new DingTalkServiceImpl();

private final String rootPath = Jenkins.get().getRootUrl();

@Override
public void onStarted(Run<?, ?> run, TaskListener listener) {
DingTalkGlobalConfig globalConfig = DingTalkGlobalConfig.getInstance();
Expand Down Expand Up @@ -241,11 +239,30 @@ private void send(Run<?, ?> run, TaskListener listener, NoticeOccasionEnum notic

// 项目信息
String projectName = job.getFullDisplayName();
String projectUrl = job.getAbsoluteUrl();
String projectUrl = job.getUrl();
try {
projectUrl = job.getAbsoluteUrl();
} catch (IllegalStateException e) {
DingTalkUtils.log(
listener,
"Get Project URL error, %s "
+ "Please set jenkins Root URL in [ System Configuration >> System >> Jenkins Location >> Jenkins URL ]",
e.toString());
}

// 构建信息
String jobName = run.getDisplayName();
String jobUrl = rootPath + run.getUrl();
String jobUrl = "";
try {
jobUrl = run.getAbsoluteUrl();
} catch (IllegalStateException e) {
DingTalkUtils.log(
listener,
"Get job URL error, %s "
+ "Please set jenkins Root URL in [ System Configuration >> System >> Jenkins Location >> Jenkins URL ]",
e.toString());
}

Check warning on line 264 in src/main/java/io/jenkins/plugins/DingTalkRunListener.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 242-264 are not covered by tests

String duration = run.getDurationString();
BuildStatusEnum statusType = getBuildStatus(noticeOccasion);

Expand Down

0 comments on commit 804897f

Please sign in to comment.