agent icon indicating copy to clipboard operation
agent copied to clipboard

Artifact download may try to write a file to the build directory

Open ticky opened this issue 7 years ago • 6 comments
trafficstars

If an artifact is downloaded, and the artifact’s name is the same as the name of the build directory, the Agent will attempt to save the artifact over the directory, and will fail because the destination path is a directory.

This is because of this code: https://github.com/buildkite/agent/blob/fe3f98124caaac5f38961625f2b978526a72442d/agent/download.go#L48-L69 and appears to have been the case for all versions of the agent.

For clarity, the example case is: Pipeline build folder: buildkite/builds/my-agent-1/my-organisation-1/pipeline-name Artifact name: pipeline-name Artifact download command: buildkite-agent artifact download pipeline-name .

Given that this behaviour is intended to be helpful, and in many cases is likely being used as intended, it might be best to simply disallow this behaviour for artifacts whose names have no directories in them.

ticky avatar Mar 19 '18 18:03 ticky

Thanks @ticky !!!! Happy to beta test any fixes y'all come up with.

chrissnell avatar Mar 19 '18 18:03 chrissnell

We’ve had another report of this today

ticky avatar Oct 29 '18 22:10 ticky

Given that this behaviour is intended to be helpful, and in many cases is likely being used as intended, it might be best to simply disallow this behaviour for artifacts whose names have no directories in them.

Agree with this approach @ticky, I'll investigate.

lox avatar Oct 29 '18 23:10 lox

My take on this is that it's dangerous behaviour. Rsync uses a trailing slash on destinations to get the different behaviour, I reckon we should do the same:

buildkite-agent artifact download pipeline-name . vs buildkite-agent artifact download pipeline-name ./

lox avatar Jul 20 '19 01:07 lox

Just wanted to chime in to mention that I too have just encountered this issue with an artifact carrying the same name as the pipeline. I worked around it easily enough (renamed the artifact) but would love to see the behavior @lox mentioned. It's the first thing I tried in an effort to resolve this issue.

splaspood avatar Sep 10 '21 18:09 splaspood

I have come across something similar to this issue, though from looking at the code snippet in the first post of this thread I'm unsure if it is expected behaviour or not. Any confirmation would be appreciated.

So the situation I found is where the first folder in the path matches the pipeline name (which seems like a reasonable approach in a monorepo implementation) the artifact is downloaded to an unexpected location

so in a monorepo approach like this (just for context):

./buildkite/pipeline.yml # this file uses the monorepo diff plugin to trigger the other pipelines project1/.buildkite/pipeline.yml project1/test/test.sh project2/.buildkite/pipeline.yml

project1 pipeline name: project1

artifact uploaded in a step: project1/test/report.xml artifact downloaded in following step: project1/test/report.xml

expected file location: project1/test/report.xml actual file location: test/report.xml

As a workaround I have renamed our pipeline to something like project1-build but this is not desirable really

dunctait avatar Jan 12 '22 10:01 dunctait