From 53cb597ddc249d7196e4dbb7f0e91153d4ca54f7 Mon Sep 17 00:00:00 2001 From: Eyal Ben Moshe Date: Sat, 28 Dec 2024 22:04:04 +0200 Subject: [PATCH] Fix Build-Info URL (#158) Co-authored-by: eyalbe4 --- .github/workflows/tests.yml | 2 +- .../agent/ArtifactoryAgentLifeCycleAdapter.java | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 296c9e9..d79bba6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,7 +18,7 @@ jobs: - name: Install Java uses: actions/setup-java@v3 with: - java-version: "8" + java-version: "11.0.25+9" distribution: "temurin" - name: Run tests diff --git a/agent/src/main/java/org/jfrog/teamcity/agent/ArtifactoryAgentLifeCycleAdapter.java b/agent/src/main/java/org/jfrog/teamcity/agent/ArtifactoryAgentLifeCycleAdapter.java index 652e9dc..49b2957 100644 --- a/agent/src/main/java/org/jfrog/teamcity/agent/ArtifactoryAgentLifeCycleAdapter.java +++ b/agent/src/main/java/org/jfrog/teamcity/agent/ArtifactoryAgentLifeCycleAdapter.java @@ -25,19 +25,22 @@ public void runnerFinished(@NotNull BuildRunnerContext runner, @NotNull BuildFin } } - private static void addBuildInfoUrlParam(BuildRunnerContext runner) { + private static void addBuildInfoUrlParam(BuildRunnerContext runner) { String artifactoryUrl = StringUtils.removeEnd(runner.getRunnerParameters().get(RunnerParameterKeys.URL), "/"); - String buildInfoUrl; if (StringUtils.endsWith(artifactoryUrl, "/artifactory")) { - // Here we can deduce the platform URL - buildInfoUrl = BuildInfoExtractorUtils.createBuildInfoUrl(StringUtils.removeEnd(artifactoryUrl, "/artifactory"), - runner.getRunnerParameters().get(BUILD_NAME), runner.getBuild().getBuildNumber(), "", "", false, true); + buildInfoUrl = createBuildInfoUrl(StringUtils.removeEnd(artifactoryUrl, "/artifactory"), (String)runner.getRunnerParameters().get(BUILD_NAME), runner.getBuild().getBuildNumber(), (String)runner.getRunnerParameters().get("org.jfrog.artifactory.build.timestamp")); } else { // Without the platform URL it would work only on Artifactory 6 buildInfoUrl = BuildInfoExtractorUtils.createBuildInfoUrl(artifactoryUrl, runner.getRunnerParameters().get(BUILD_NAME), runner.getBuild().getBuildNumber(), "", "", false, false); } + runner.getBuild().addSharedSystemProperty(BUILD_URL + "." + runner.getBuild().getBuildId() + "." + runner.getId(), buildInfoUrl); - } + } + + private static String createBuildInfoUrl(String platformUrl, String buildName, String buildNumber, String timeStamp) { + String timestampUrlPart = StringUtils.isBlank(timeStamp) ? "" : "/" + timeStamp; + return String.format("%s/%s/%s%s/%s", platformUrl + "/ui/builds", buildName, buildNumber, timestampUrlPart, "published"); + } }