Artifact seems to be removed during source code checkout
Asked by David Rydg?rd:

I have an artifact dependency, the artifact being created by a previous stage in the plan. As 'destination directory' for the dependency, I have put 'Artifacts'.

There is a script task that just runs the line *dir Artifacts* . This works fine, and in the logs I can see that the artifact is in the 'Artifacts' directory. This task is followed by a source code checkout task. The source code checkout is then followed by a task which, again, just runs *dir Artifacts*. This time, it gives an error message because, as it seems, the 'Artifacts' directory does not exist anymore.

I can see in the logs that, as part of the source code checkout, Bamboo "cleans" the build directory. I suppose this removes the 'Artifacts' directory. But if that is the case, how can I use Artifacts after doing a source code checkout?


Answers:
author: Eduardo Alvarenga
body: Hello [@David Rydg?rd](/t5/user/viewprofilepage/user-id/5355301)

Welcome to the **Atlassian Community**!

There's a possibility the "Force Clean Build" property is enabled in the "Source Code Checkout" task, which will instruct the Agent to remove everything from the build-dir before running the Git checkout during Stage 2 execution.

Also, the Checkout Task in Bamboo will retry the operation in case of failure, like having files or folders in the checkout folder that are not part of the repository. When retrying, Bamboo cleans up the folder to have a clean checkout. That action may be removing the files you expect to see in the second stage. As you check out the code in place, there's a chance that Bamboo is doing that.

To fix that, set the "Checkout Directory" in the "Source Code Checkout" task properties to a subfolder within the build directory. That will allow you to separate the repository data from the artifacts, which will not conflict with files from a different stage.

It is also possible to remove the Artifact Dependency and add an "Artifact Download" task in the Second Stage Jobs so you can control exactly what and when artifacts will be downloaded.

More information can be found on the link below:

* [Sharing Artifacts](https://confluence.atlassian.com/bamboo/sharing-artifacts-359400060.html)

Thank you,

Eduardo Alvarenga  
Atlassian Support APAC

**--please don't forget to Accept the answer if the reply is helpful--**

comments: author: David Rydg?rd
body: Great, thank you for a clear explanation!


author: Shashank Kumar
body: Hello David,

Welcome to Atlassian Community

I can understand you have the below structure for your plan.

1. First script task just runs the dir Artifacts which lists the artifcats from the build directory.

2. Source code checkout task checks out the repo

3. Third script task fails to list the directory.

You have mentioned that the script task is cleans the build directory, so we'll need to stop that. To do that you can go to the script task in your plan configuration and uncheck the option of "Force clean Build", see below

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/289706i93576FAD5E7E9333/image-size/large?v=v2&px=999 "image.png")

Let me know if this works for you.

Regards,

Shashank Kumar

**\*\*please don't forget to Accept the answer if your query was answered\*\***