Skip to content

Commit a1be636

Browse files
authored
Merge pull request #3607 from buildkite/fix-double-slashed-custom-bucket-artifacts
PS-1470 Fix issue where artifacts uploaded to custom s3 buckets would have a double slash prefix
2 parents 3cf00bd + 537c838 commit a1be636

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

.buildkite/steps/e2e-tests.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
if [[ -z "${BUILDKITE_TRIGGERED_FROM_BUILD_ID}" ]] ; then
4+
if [[ -z "${BUILDKITE_TRIGGERED_FROM_BUILD_ID:-}" ]] ; then
55
# For now, e2e test the agent that's currently running
6-
export CI_E2E_TESTS_AGENT_PATH="$(which buildkite-agent)"
6+
CI_E2E_TESTS_AGENT_PATH="$(which buildkite-agent)"
7+
export CI_E2E_TESTS_AGENT_PATH
78
else
89
# Download the artifact from the triggering build
910
ARTIFACT="pkg/buildkite-agent-$(go env GOOS)-$(go env GOARCH)"

internal/artifact/s3_uploader.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"net/url"
77
"os"
8+
"path"
89
"slices"
910
"strings"
1011
"time"
@@ -83,11 +84,10 @@ func (u *S3Uploader) URL(artifact *api.Artifact) string {
8384
baseUrl = os.Getenv("BUILDKITE_S3_ACCESS_URL")
8485
}
8586

86-
url, _ := url.Parse(baseUrl)
87+
uri, _ := url.Parse(baseUrl)
88+
uri.Path = path.Join(uri.Path, u.artifactPath(artifact))
8789

88-
url.Path += u.artifactPath(artifact)
89-
90-
return url.String()
90+
return uri.String()
9191
}
9292

9393
func (u *S3Uploader) CreateWork(artifact *api.Artifact) ([]workUnit, error) {

internal/e2e/artifact_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build e2e
2+
3+
package e2e
4+
5+
import (
6+
"testing"
7+
)
8+
9+
// Test that an agent can upload and download an artifact across different steps in the same build
10+
func TestArtifactUploadDownload(t *testing.T) {
11+
ctx := t.Context()
12+
13+
tc := newTestCase(t, "artifact_upload_download.yaml")
14+
15+
tc.startAgent()
16+
build := tc.triggerBuild()
17+
state := tc.waitForBuild(ctx, build)
18+
if got, want := state, "passed"; got != want {
19+
t.Errorf("Build state = %q, want %q", got, want)
20+
}
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
agents:
2+
queue: {{ .queue }}
3+
steps:
4+
- key: upload
5+
commands:
6+
- echo "hello world" > artifact.txt
7+
- buildkite-agent artifact upload artifact.txt
8+
- key: download
9+
depends_on: upload
10+
commands:
11+
- buildkite-agent artifact download artifact.txt . && if [[ $(cat artifact.txt) == "hello world" ]]; then exit 0; else exit 1; fi

0 commit comments

Comments
 (0)