Is there a way to change directory on AWS codebuild

Zipper picture Zipper · Mar 2, 2017 · Viewed 12k times · Source

With Snap-CI going away I've been trying to get our builds working on AWS CodeBuild. I have my buildspec.yml built out, but changing directories doesn't seem to work.

version: 0.1

phases:
  install:
    commands:
      - apt-get update -y
      - apt-get install -y node
      - apt-get install -y npm
  build:
    commands:
      - cd MyDir  //Expect to be in MyDir now
      - echo `pwd` //Shows /tmp/blablabla/ instead of /tmp/blablabla/MyDir
      - npm install //Fails because I'm not in the right directory
      - bower install
      - npm run ci
  post_build:
    commands:
      - echo Build completed on `date`
artifacts:
  files:
    - MyDir/MyFile.war
  discard-paths: yes

It seems like this should be fairly simple, but so far I haven't had any luck getting this to work.

Answer

Eric Nord picture Eric Nord · Jul 15, 2017

If you change the buildspec.yml version to 0.2 then the shell keeps its settings. In version: 0.1 you get a clean shell for each command.

enjoy ;)