Summary
When SCPing an artifact of multiple nested directories + files and the location of the artifact is not defined as the root of the working directory; the location directory is also created at the destination, when instead we just want the contents of the location to be copied (not the location directory itself).
It's easier to articulate with the example below.
Steps to Reproduce
- Source directory:
+ dir working_directory
| + dir build
| + file index.html
| + dir css
| + file style.css
- Artifact definition:
* Location: build
* Copy pattern: **
- SCP Task to copy Artifact to a remote path: /var/www/public_html (ensure this path exists on the remote or we will hit
BAM-14439 which will change the result)
Expected Results
The remote should end up with: /var/www/public_html/index.html
Actual Results
The remote ends up with /var/www/public_html/build/index.html
Notes
- This behavior is completely different (and aligns with what's expected) if in the above example, the css subdirectory and style.css do not exist.
- The difference in the above scenario, seems to be the recursive copy. It's like performing:
- scp -r build user@host:/var/www/public_html instead of performing:
- scp -r build/* user@host:/var/www/public_html
- The Artifact Download task downloads the same artifact as expected, without creating the build directory.
- If the target directory (e.g. public_html) doesn't exist, the build folder isn't created (
BAM-14439)
- If the same artifact is downloaded in a separate stage into the root of the working directory, SCP copies it as expected.
Workaround
- Create a separate stage in the plan which has:
- Artifact Download task: This will download the artifact we were previously SCPing, to the root of the working directory of the new stage. You'll need to make sure the definition of the previous artifact is shared so it can be retrieved in another stage.
- SCP task that references the Artifact downloaded and copies it to the remote location.
or
- Use a script task to SCP the files like this example:
sshpass -p ${bamboo.scp_password} scp -r build/* user@host:/var/www/public_html