Skip to content

Commit d7c64c0

Browse files
author
Alex Ford
committed
Convert artifact plugin to rsync plugin.
A friendly-fork of buildkite-plugins/rsync-buildkite-plugin to support `rsync`-based file transfers.
1 parent c334295 commit d7c64c0

8 files changed

Lines changed: 104 additions & 270 deletions

File tree

.buildkite/pipeline.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

.github/boomper.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

.github/release-drafter.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

README.md

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,75 @@
1-
# Artifacts Buildkite Plugin
1+
# `rsync` Buildkite Plugin
22

3-
A [Buildkite plugin](https://buildkite.com/docs/agent/v3/plugins) for uploading and downloading artifacts.
3+
A [Buildkite plugin](https://buildkite.com/docs/agent/v3/plugins) for
4+
performing file transfers via
5+
[`rsync`](https://linux.die.net/man/1/rsync). The plugin invokes `rsync`
6+
in the `pre` or `post` command phase to provide an artifact-like upload
7+
and download capacity.
48

5-
## Uploading artifacts
9+
## Examples
610

7-
This functionality duplicates the [artifact_paths]() property in the pipeline yaml files.
11+
Upload a build product directory into a build-specific output directory on
12+
a remote store:
813

914
```yml
1015
steps:
1116
- plugins:
12-
artifacts#v1.2.0:
13-
upload: "log/**/*.log"
17+
uw-ipd/rsync#v0.1:
18+
post: "-Rrv bin remote:/build/${BUILDKITE_BUILD_NUMBER}"
1419
```
1520
16-
or
21+
Upload a glob of files, note that artifact-path extended globbing (eg.
22+
`path/**/*.log`) is *not* supported:
1723

1824
```yml
1925
steps:
2026
- plugins:
21-
artifacts#v1.2.0:
22-
upload: [ "log/**/*.log", "debug/*.error" ]
27+
uw-ipd/rsync#v0.1:
28+
post: "-Rrv log/*/*.log remote:/build/${BUILDKITE_BUILD_NUMBER}"
2329
```
2430

25-
## Downloading artifacts
26-
27-
This downloads artifacts matching globs to the local filesystem. See [downloading artifacts](https://buildkite.com/docs/agent/cli-artifact#downloading-artifacts) for more details.
31+
`${VAR}` is interpolated at pipeline-upload time, not step evaluation
32+
time. Use `$${VAR}` to perform step-time interpolation of environment
33+
variables:
2834

2935
```yml
3036
steps:
3137
- plugins:
32-
artifacts#v1.2.0:
33-
download: "log/**/*.log"
38+
uw-ipd/rsync#v0.1:
39+
post: "-Rrv bin remote:/build/$${BUILDKITE_JOB_ID}"
3440
```
3541

36-
or
42+
Upload via multiple invocations:
3743

3844
```yml
3945
steps:
4046
- plugins:
41-
artifacts#v1.2.0:
42-
download: [ "log/**/*.log", "debug/*.error" ]
47+
uw-ipd/rsync#v0.1:
48+
post:
49+
- "-Rrv bin remote:/build/${BUILDKITE_BUILD_NUMBER}"
50+
- "-Rrv logs/*/*.txt remote:/build/${BUILDKITE_BUILD_NUMBER}/$${BUILDKITE_JOB_ID}"
4351
```
4452

45-
## Configuration
46-
47-
### `upload`
53+
Download *before* a command executes via the `pre` step:
4854

49-
A glob pattern, or array of glob patterns, for files to upload.
50-
51-
### `download`
55+
```yml
56+
steps:
57+
- plugins:
58+
uw-ipd/rsync#v0.1:
59+
pre: "-rv remote:/build/ccache ./ccache"
60+
```
5261

53-
A glob pattern, or array of glob patterns, for files to download.
62+
## Configuration
5463

55-
### `step` (optional)
64+
### `pre`
5665

57-
The job UUID or name to download the artifact from.
66+
An rsync argument string, or array of rsync argument strings, to be
67+
executed before `command`.
5868

59-
### `build` (optional)
69+
### `post`
6070

61-
The build UUID to download the artifact from.
71+
An rsync argument string, or array of rsync argument strings, to be
72+
executed after `command`.
6273

6374
## License
6475

hooks/post-command

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,32 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
if [[ "${BUILDKITE_PLUGIN_ARTIFACTS_DEBUG:-false}" =~ (true|on|1) ]] ; then
4+
if [[ "${BUILDKITE_PLUGIN_RSYNC_DEBUG:-false}" =~ (true|on|1) ]] ; then
55
echo "--- :hammer: Enabling debug mode"
66
set -x
77
fi
88

9-
args=()
10-
11-
if [[ -n "${BUILDKITE_PLUGIN_ARTIFACTS_JOB:-}" ]] ; then
12-
args+=("--job" "${BUILDKITE_PLUGIN_ARTIFACTS_JOB}")
13-
fi
14-
159
paths=()
1610

17-
if [[ -n "${BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD:-}" ]] ; then
18-
paths+=("$BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD")
11+
if [[ -n "${BUILDKITE_PLUGIN_RSYNC_POST:-}" ]] ; then
12+
paths+=("$BUILDKITE_PLUGIN_RSYNC_POST")
1913
fi
2014

2115
while IFS='=' read -r path _ ; do
22-
if [[ $path =~ ^(BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_[0-9]+) ]] ; then
16+
if [[ $path =~ ^(BUILDKITE_PLUGIN_RSYNC_POST_[0-9]+) ]] ; then
2317
paths+=("${!path}")
2418
fi
2519
done < <(env | sort)
2620

27-
workdir=${BUILDKITE_PLUGIN_ARTIFACTS_WORKDIR:-.}
21+
workdir=${BUILDKITE_PLUGIN_RSYNC_WORKDIR:-.}
2822

2923
pushd "${workdir}"
3024
trap popd EXIT
3125

32-
if [ "${#paths[@]}" -eq 1 ]; then
33-
if [ "${#args[@]}" -gt 0 ]; then
34-
echo "--- Uploading artifacts with args: ${args[*]}"
26+
echo "--- rsync-ing "
3527

36-
buildkite-agent artifact upload "${args[@]}" "${paths[*]}"
37-
else
38-
echo "--- Uploading artifacts"
39-
40-
buildkite-agent artifact upload "${paths[*]}"
41-
fi
42-
elif [ "${#paths[@]}" -gt 1 ]; then
43-
if [ "${#args[@]}" -gt 0 ]; then
44-
echo "--- Uploading artifacts with args: ${args[*]}"
45-
46-
for path in "${paths[@]}"
47-
do
48-
buildkite-agent artifact upload "${args[@]}" "$path"
49-
done
50-
else
51-
echo "--- Uploading artifacts"
52-
53-
for path in "${paths[@]}"
54-
do
55-
buildkite-agent artifact upload "$path"
56-
done
57-
fi
58-
fi
28+
for path in "${paths[@]}"
29+
do
30+
## `eval` to support step-time varibles in the command
31+
eval rsync $path
32+
done

hooks/pre-command

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,32 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
if [[ "${BUILDKITE_PLUGIN_ARTIFACTS_DEBUG:-false}" =~ (true|on|1) ]] ; then
4+
if [[ "${BUILDKITE_PLUGIN_RSYNC_DEBUG:-false}" =~ (true|on|1) ]] ; then
55
echo "--- :hammer: Enabling debug mode"
66
set -x
77
fi
88

9-
args=()
10-
11-
if [[ -n "${BUILDKITE_PLUGIN_ARTIFACTS_STEP:-}" ]] ; then
12-
args+=("--step" "${BUILDKITE_PLUGIN_ARTIFACTS_STEP}")
13-
fi
14-
15-
if [[ -n "${BUILDKITE_PLUGIN_ARTIFACTS_BUILD:-}" ]] ; then
16-
args+=("--build" "${BUILDKITE_PLUGIN_ARTIFACTS_BUILD}")
17-
fi
18-
199
paths=()
2010

21-
if [[ -n "${BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD:-}" ]] ; then
22-
paths+=("$BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD")
11+
if [[ -n "${BUILDKITE_PLUGIN_RSYNC_PRE:-}" ]] ; then
12+
paths+=("$BUILDKITE_PLUGIN_RSYNC_PRE")
2313
fi
2414

2515
while IFS='=' read -r path _ ; do
26-
if [[ $path =~ ^(BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD_[0-9]+) ]] ; then
16+
if [[ $path =~ ^(BUILDKITE_PLUGIN_RSYNC_PRE_[0-9]+) ]] ; then
2717
paths+=("${!path}")
2818
fi
2919
done < <(env | sort)
3020

31-
workdir="${BUILDKITE_PLUGIN_ARTIFACTS_WORKDIR:-.}"
21+
workdir=${BUILDKITE_PLUGIN_RSYNC_WORKDIR:-.}
3222

33-
if [ "${#paths[@]}" -eq 1 ]; then
34-
if [ "${#args[@]}" -gt 0 ]; then
35-
echo "--- Downloading artifacts with args: ${args[*]}"
23+
pushd "${workdir}"
24+
trap popd EXIT
3625

37-
buildkite-agent artifact download "${args[@]}" "${paths[*]}" "${workdir}"
38-
else
39-
echo "--- Downloading artifacts"
26+
echo "--- rsync-ing "
4027

41-
buildkite-agent artifact download "${paths[*]}" "${workdir}"
42-
fi
43-
elif [ "${#paths[@]}" -gt 1 ]; then
44-
if [ "${#args[@]}" -gt 0 ]; then
45-
echo "--- Downloading artifacts with args: ${args[*]}"
46-
47-
for path in "${paths[@]}"
48-
do
49-
buildkite-agent artifact download "${args[@]}" "$path" "${workdir}"
50-
done
51-
else
52-
echo "--- Downloading artifacts"
53-
54-
for path in "${paths[@]}"
55-
do
56-
buildkite-agent artifact download "$path" "${workdir}"
57-
done
58-
fi
59-
fi
28+
for path in "${paths[@]}"
29+
do
30+
## `eval` to support step-time varibles in the command
31+
eval rsync $path
32+
done

renovate.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)