AWS CodeBuild - cd: can't cd to /codebuild/output/src... 错误和未找到工件路径

Posted

技术标签:

【中文标题】AWS CodeBuild - cd: can\'t cd to /codebuild/output/src... 错误和未找到工件路径【英文标题】:AWS CodeBuild - cd: can't cd to /codebuild/output/src... error and artifacts path not foundAWS CodeBuild - cd: can't cd to /codebuild/output/src... 错误和未找到工件路径 【发布时间】:2019-06-25 03:50:02 【问题描述】:

================

我是 AWS CodeBuild 的新手。我们是第一次尝试。我设置了我的 Buildspec.yml 文件,当我运行它时,我收到错误指示它 cd: can't cd to /codebuild/output/src.... 在整个构建运行过程中,但它每次都会进入下一步忽略错误。但是,当它到达工件步骤时,它找不到工件路径。我已经尝试了很多次工件的迭代:文件:没有运气的语句。我不确定 cd 错误和工件问题是否相关。

这是当前的 Buildspec 文件。我还尝试了几种不同版本的“文件:”语句,包括 - '**/*'

buildspec.yml

version: 0.2

phases:
  install:
    commands:
      - echo Nothing to do in the install phase...
  pre_build:
    commands:
      - echo Nothing to do in the pre_build phase...
  build:
    commands:
      - echo Build started on `date`
      - echo $CODEBUILD_SRC_DIR
      - uServices/hello-world-java/gradlew build
  post_build:
    commands:
      - echo Build completed on `date`
artifacts:
  files:
    - uServices/hello-world-java/build/distributions/*

代码构建的输出

[Container] 2019/01/31 14:19:42 Waiting for agent ping
[Container] 2019/01/31 14:19:43 Waiting for DOWNLOAD_SOURCE
[Container] 2019/01/31 14:19:44 Phase is DOWNLOAD_SOURCE
[Container] 2019/01/31 14:19:44 CODEBUILD_SRC_DIR=/codebuild/output/src590503358/src/github.com/SomosEngineering/tss-modern.git
[Container] 2019/01/31 14:19:44 YAML location is /codebuild/output/src590503358/src/github.com/SomosEngineering/tss-modern.git /buildspec.yml
[Container] 2019/01/31 14:19:44 Processing environment variables
[Container] 2019/01/31 14:19:44 Moving to directory /codebuild/output/src590503358/src/github.com/SomosEngineering/tss-modern.git
[Container] 2019/01/31 14:19:44 Registering with agent
[Container] 2019/01/31 14:19:44 Phases found in YAML: 4
[Container] 2019/01/31 14:19:44 POST_BUILD: 1 commands
[Container] 2019/01/31 14:19:44 INSTALL: 1 commands
[Container] 2019/01/31 14:19:44 PRE_BUILD: 1 commands
[Container] 2019/01/31 14:19:44 BUILD: 3 commands
[Container] 2019/01/31 14:19:44 Phase complete: DOWNLOAD_SOURCE Success: true
[Container] 2019/01/31 14:19:44 Phase context status code: Message:
[Container] 2019/01/31 14:19:44 Entering phase INSTALL
[Container] 2019/01/31 14:19:44 Running command echo Nothing to do in the install phase...
/codebuild/output/tmp/script.sh: 1: cd: can't cd to /codebuild/output/src590503358/src/github.com/SomosEngineering/tss-modern.git
Nothing to do in the install phase...
 [Container] 2019/01/31 14:19:44 Phase complete: INSTALL Success: true
[Container] 2019/01/31 14:19:44 Phase context status code: Message:
[Container] 2019/01/31 14:19:45 Entering phase PRE_BUILD
[Container] 2019/01/31 14:19:45 Running command echo Nothing to do in the pre_build phase...
/codebuild/output/tmp/script.sh: 1: cd: can't cd to /codebuild/output/src590503358/src/github.com/SomosEngineering/tss-modern.git
Nothing to do in the pre_build phase...
 [Container] 2019/01/31 14:19:45 Phase complete: PRE_BUILD Success: true
[Container] 2019/01/31 14:19:45 Phase context status code: Message:
[Container] 2019/01/31 14:19:45 Entering phase BUILD
[Container] 2019/01/31 14:19:45 Running command echo Build started on `date`
/codebuild/output/tmp/script.sh: 1: cd: can't cd to /codebuild/output/src590503358/src/github.com/SomosEngineering/tss-modern.git
Build started on Thu Jan 31 14:19:45 UTC 2019
 [Container] 2019/01/31 14:19:45 Running command echo $CODEBUILD_SRC_DIR
/codebuild/output/tmp/script.sh: 1: cd: can't cd to /codebuild/output/src590503358/src/github.com/SomosEngineering/tss-modern.git
/codebuild/output/src590503358/src/github.com/SomosEngineering/tss-modern.git
 [Container] 2019/01/31 14:19:45 Running command uServices/hello-world-java/gradlew build
/codebuild/output/tmp/script.sh: 1: cd: can't cd to /codebuild/output/src590503358/src/github.com/SomosEngineering/tss-modern.git
Downloading https://services.gradle.org/distributions/gradle-3.5-bin.zip
..........................................................................................................................................................................................................................................................................................
Unzipping /root/.gradle/wrapper/dists/gradle-3.5-bin/daoimhu7k5rlo48ntmxw2ok3e/gradle-3.5-bin.zip to /root/.gradle/wrapper/dists/gradle-3.5-bin/daoimhu7k5rlo48ntmxw2ok3e
Set executable permissions for: /root/.gradle/wrapper/dists/gradle-3.5-bin/daoimhu7k5rlo48ntmxw2ok3e/gradle-3.5/bin/gradle
Starting a Gradle Daemon (subsequent builds will be faster)
:buildEnvironment
 ------------------------------------------------------------
Root project
------------------------------------------------------------
 classpath
No dependencies
 BUILD SUCCESSFUL
 Total time: 8.74 secs
 [Container] 2019/01/31 14:19:56 Phase complete: BUILD Success: true
[Container] 2019/01/31 14:19:56 Phase context status code: Message:
[Container] 2019/01/31 14:19:56 Entering phase POST_BUILD
[Container] 2019/01/31 14:19:56 Running command echo Build completed on `date`
/codebuild/output/tmp/script.sh: 1: cd: can't cd to /codebuild/output/src590503358/src/github.com/SomosEngineering/tss-modern.git
Build completed on Thu Jan 31 14:19:56 UTC 2019
 [Container] 2019/01/31 14:19:56 Phase complete: POST_BUILD Success: true
[Container] 2019/01/31 14:19:56 Phase context status code: Message:
[Container] 2019/01/31 14:19:56 Expanding base directory path: .
[Container] 2019/01/31 14:19:56 Assembling file list
[Container] 2019/01/31 14:19:56 Expanding /codebuild/output/tmp/script.sh: 1: cd: can't cd to /codebuild/output/src590503358/src/github.com/SomosEngineering/tss-modern.git
.
[Container] 2019/01/31 14:19:56 Expanded to /codebuild/output/tmp/script.sh: 1: cd: can't cd to /codebuild/output/src590503358/src/github.com/SomosEngineering/tss-modern.git
/codebuild/output/tmp/script.sh: 1: cd: can't cd to /codebuild/output/src590503358/src/github.com/SomosEngineering/tss-modern.git
.
[Container] 2019/01/31 14:19:56 Skipping invalid artifact path /codebuild/output/tmp/script.sh: 1: cd: can't cd to /codebuild/output/src590503358/src/github.com/SomosEngineering/tss-modern.git
/codebuild/output/tmp/script.sh: 1: cd: can't cd to /codebuild/output/src590503358/src/github.com/SomosEngineering/tss-modern.git
.

[容器] 2019/01/31 14:19:56 阶段完成:UPLOAD_ARTIFACTS 成功:false [容器] 2019/01/31 14:19:56 阶段上下文状态代码:CLIENT_ERROR 消息:找不到 /codebuild/output/tmp/script.sh 的匹配基目录路径:1:cd:无法 cd 到 /codebuild /output/src590503358/src/github.com/SomosEngineering/tss-modern.git

总结


在我的开发区域中,我可以运行 Gradle 并查看 .zip 工件 坐在以下目录中,如下所示。我希望代码构建 找到它并将其加载到 S3。 [clipford@NVA-1a-TSS-DEV01

分布]$ pwd

/home/clipford/work/tss-modern/uServices/hello-world-java/build/distributions

[clipford@NVA-1a-TSS-DEV01 分布]$ ls

tss-modern-clipford.zip

【问题讨论】:

【参考方案1】:

我最终尝试从一个亚马逊 S3 容器构建它,构建工作完全正常。然后我回到 GitHub 版本,与无法 cd 到 codebuild 目录相关的问题神奇地消失了。 (我也不相信魔法,但认为这是亚马逊的问题)。

工件未加载的问题与我们项目中的工件位于不属于 GitHub 存储库的目录中的事实有关。它实际上在 .gitignore 中被忽略了。工件目录是在构建时创建的,由于它在 .gitignore 中被忽略并且不是 repo 的一部分,因此代码构建找不到工件并且无法将其加载到 S3。

【讨论】:

我发现即使我将路径添加到 GitHub 存储库中,分发文件仍然不存在。我通过在这些存储库中添加 ls -al 语句来验证这一点。尚不确定如何解决此问题。

以上是关于AWS CodeBuild - cd: can't cd to /codebuild/output/src... 错误和未找到工件路径的主要内容,如果未能解决你的问题,请参考以下文章

AWS CodePipeline:同时运行多个管道

AWS CodePipeline 能否在不劫持 CodeBuild 的工件设置的情况下触发 AWS CodeBuild?

AWS Batch 与 AWS CodeBuild

无法将更改从 AWS CodeBuild 推送到 AWS CodeCommit

AWS CodePipeline 不遵守 CodeBuild 设置

使用 AWS CDK 创建用于构建 Docker 映像的 CodeBuild 项目