Skip to content

Commit a9ee3a4

Browse files
paustin01claude
andcommitted
fix: trim trailing slash from Rundeck server URL
Prevents double slashes in the generated build URL when RD_JOB_SERVERURL has a trailing slash. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d3b6b6e commit a9ee3a4

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

internal/cicd/detector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func detectRundeck(d *DetectedValues) {
372372
serverURL := os.Getenv("RD_JOB_SERVERURL")
373373
execID := os.Getenv("RD_JOB_EXECID")
374374
if serverURL != "" && execID != "" {
375-
d.BuildURL = fmt.Sprintf("%s/execution/show/%s", serverURL, execID)
375+
d.BuildURL = fmt.Sprintf("%s/execution/show/%s", strings.TrimSuffix(serverURL, "/"), execID)
376376
}
377377

378378
// Use job name as product fallback

internal/cicd/detector_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,44 @@ func TestDetectRundeck(t *testing.T) {
176176
}
177177
}
178178

179+
func TestDetectRundeckWithTrailingSlash(t *testing.T) {
180+
// Save and clear environment
181+
originalEnv := make(map[string]string)
182+
envVars := []string{
183+
"RD_JOB_ID", "RD_JOB_EXECID", "RD_JOB_SERVERURL",
184+
"GITHUB_ACTIONS", "GITLAB_CI", "JENKINS_URL",
185+
}
186+
for _, key := range envVars {
187+
originalEnv[key] = os.Getenv(key)
188+
os.Unsetenv(key)
189+
}
190+
defer func() {
191+
for key, val := range originalEnv {
192+
if val != "" {
193+
os.Setenv(key, val)
194+
} else {
195+
os.Unsetenv(key)
196+
}
197+
}
198+
}()
199+
200+
// Set Rundeck environment with trailing slash in server URL
201+
os.Setenv("RD_JOB_ID", "abc-123")
202+
os.Setenv("RD_JOB_EXECID", "1359")
203+
os.Setenv("RD_JOB_SERVERURL", "https://rundecksupernew.meprod.net/")
204+
205+
detected := Detect()
206+
207+
if detected.System != SystemRundeck {
208+
t.Errorf("Expected system %s, got %s", SystemRundeck, detected.System)
209+
}
210+
211+
expectedURL := "https://rundecksupernew.meprod.net/execution/show/1359"
212+
if detected.BuildURL != expectedURL {
213+
t.Errorf("Expected build URL %s, got %s (should not have double slash)", expectedURL, detected.BuildURL)
214+
}
215+
}
216+
179217
func TestDetectUnknown(t *testing.T) {
180218
// Clear all CI environment variables
181219
ciEnvVars := []string{

0 commit comments

Comments
 (0)