15

So I am attempting to setup CodeDeploy for my application and I keep getting an error during the BeforeInstall part of the deployment. Below is the error.

Error Code UnknownError
Script Name
Message No such file or directory - /opt/codedeploy-agent/deployment-root/06100f1b-5495-42d9-bd01-f33d59fb5deb/d-NL5K1THE8/deployment-archive/appspec.yml
Log Tail

I assumed this meant the YAML file was in the wrong place. However it is in the root directory of my revision. I have tried using a simple AppSpec file like so instead of a more complex one.

    ## YAML Template.
---
version: 0.0
os: linux
files:
  - source: /
    destination: /home/ubuntu/www

More or less since this is a first deployment I want it to add all files in the revision to the public directory on the web server.

I am tearing my hair out over this and I feel it is a simple issue. I have the IAM policies and roles correct and I have CodeDeploy setup and running on my instance I am trying to deploy to.

wmfrancia
  • 1,186
  • 2
  • 9
  • 24

5 Answers5

34

It seems to think you had a successful deploy at some point.

Go into /opt/codedeploy-agent/deployment-root/deployment-instructions/ and delete all the files in there. Then it won't look for this last deploy.

Levitron
  • 1,013
  • 8
  • 14
  • 2
    This is actually the answer (or at least it was in my case). – mcarpenter Jun 17 '16 at 19:23
  • 1
    Worked, except I was on windows so path is `C:\ProgramData\Amazon\CodeDeploy\deployment-instructions` – Kevin Smith Oct 02 '17 at 16:14
  • Worked, you saved my day! – Chamin Wickramarathna Jul 26 '18 at 04:47
  • Wasted a whole day before I found this! Not sure how the disconnect happens but in my case all I did was forget to push one of the files in the appSpec. Once I replaced that file in source, this error kept occurring. Thanks @Levitron – headz68 Aug 01 '19 at 18:14
  • Why is this the solution ? Imagine, you deploy from test to staging, a week later you clone staging to get a live or another staging instance going. You then deploy again and run into this error.. and this solution here fixes it. How come? How do you begin to figure this out if there is no stackoverflow answer yet? :-/ – LittleTiger Oct 20 '20 at 01:48
4

I just had this SAME problem and I figured it out! Make sure your AppSpec file has the right EXTENSION! I was using yaml and not yml, now everything works perfectly.

redband
  • 287
  • 1
  • 15
2

I made it work like this:

I had a couple of failed deployments for various reasons. The thing is that CD keeps in the EC2 instance and in the path /opt/codedeploy-agent/deployment-root/​ a folder named by the ID of the failed deployment [a very long alphanumeric sting] . Delete this folder and create a new deployment [from the aws UI console] and redeploy the application. This way the appspec.yml file that is in the wrong place will be deleted. It should now succeed.

Extra Notice:

CD does not rewrite files [that have not been created by it's specific deployment] CodeDeploy does not deploy in a folder that there is already code[files] as it does not want to interfere with different CD deployments and/or other CI/CD tools [like Jenkins]. It only deploys in a path that has already deploy code with the specific deployment.

You can empty the folder where your deployment want to happen and redeploy your code via CD.

Kostas Demiris
  • 2,655
  • 3
  • 34
  • 62
0

When you login to the host, do you see the appspec.yml file in the directory there? If not are you positive it has been checked in with the rest of your deployed code?

Chris Munns
  • 116
  • 1
  • 6
  • It is the first deployment so there is no directory in the host yet that has the AppSpec.yml file I do see it in the root directory in the compressed tar file that was setup for the revision to deploy in S3 – wmfrancia Apr 20 '15 at 17:11
  • Hrmm, that tarball should end up in /opt/codedeploy-agent/deployment-root/// regardless of a failure or not ( as far as I know) even if its the first deploy. Does that end up there with the rest of your contents or no? – Chris Munns Apr 20 '15 at 20:14
0

Just encountered this issue too. In my case, the revision zip file extracts into a directory when deployed. Because of that /opt/codedeploy-agent/deployment-root/xxx/xxx/deployment-archive contains the parent directory of my revision files (instead of the actual revision files).

The key is to compress your revision without the parent directory. In mac terminal,

cd your-app-directory-containing-appspec
zip -r app.zip . 
phpd
  • 501
  • 4
  • 10