Skip to content

Commit 804897f

Browse files
authored
fix: get project/job url error when not config root url (#252)
Signed-off-by: BobDu <i@bobdu.cc>
1 parent 4736543 commit 804897f

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/main/java/io/jenkins/plugins/DingTalkRunListener.java

+21-4
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public class DingTalkRunListener extends RunListener<Run<?, ?>> {
4545

4646
private final DingTalkServiceImpl service = new DingTalkServiceImpl();
4747

48-
private final String rootPath = Jenkins.get().getRootUrl();
49-
5048
@Override
5149
public void onStarted(Run<?, ?> run, TaskListener listener) {
5250
DingTalkGlobalConfig globalConfig = DingTalkGlobalConfig.getInstance();
@@ -241,11 +239,30 @@ private void send(Run<?, ?> run, TaskListener listener, NoticeOccasionEnum notic
241239

242240
// 项目信息
243241
String projectName = job.getFullDisplayName();
244-
String projectUrl = job.getAbsoluteUrl();
242+
String projectUrl = job.getUrl();
243+
try {
244+
projectUrl = job.getAbsoluteUrl();
245+
} catch (IllegalStateException e) {
246+
DingTalkUtils.log(
247+
listener,
248+
"Get Project URL error, %s "
249+
+ "Please set jenkins Root URL in [ System Configuration >> System >> Jenkins Location >> Jenkins URL ]",
250+
e.toString());
251+
}
245252

246253
// 构建信息
247254
String jobName = run.getDisplayName();
248-
String jobUrl = rootPath + run.getUrl();
255+
String jobUrl = "";
256+
try {
257+
jobUrl = run.getAbsoluteUrl();
258+
} catch (IllegalStateException e) {
259+
DingTalkUtils.log(
260+
listener,
261+
"Get job URL error, %s "
262+
+ "Please set jenkins Root URL in [ System Configuration >> System >> Jenkins Location >> Jenkins URL ]",
263+
e.toString());
264+
}
265+
249266
String duration = run.getDurationString();
250267
BuildStatusEnum statusType = getBuildStatus(noticeOccasion);
251268

0 commit comments

Comments
 (0)