有没有办法在AWS codebuild上更改目录

问题描述 投票:8回答:2

随着Snap-CI的消失,我一直在努力让我们的构建工作在AWS CodeBuild上。我已经构建了buildspec.yml,但是更改目录似乎不起作用。

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

看起来这应该是相当简单的,但到目前为止我还没有运气好。

amazon-web-services continuous-integration aws-codebuild
2个回答
22
投票

如果将buildspec.yml版本更改为0.2,则shell将保留其设置。在版本:0.1中,每个命令都有一个干净的shell。

请享用 ;)


11
投票

CodeBuild中的每个命令都在针对源根目录的单独shell中运行(从CODEBUILD_SRC_DIR环境变量访问源的根目录)。

你可能的选择是

  • 短路命令在同一个shell下运行:当你有相对简单的buildspec(和你的)一样工作。

commands: - cd MyDir && npm install && bower install - cd MyDir && npm run ci

  • 将命令从buildspec移动到脚本并具有更多控制(对于更复杂的构建逻辑非常有用)。

commands: - ./mybuildscipt.sh

如果其中任何一项对您有用,请告诉我。

- 编辑 -

CodeBuild已经启动了buildspec v0.2,不再需要这种解决方法。

© www.soinside.com 2019 - 2024. All rights reserved.