amazon-web-services - 无法在 CodeBuild 中运行 bash 脚本

标签 amazon-web-services aws-codebuild

我有以下buildspec.yml

version: 0.2

env:
  shell: bash
phases:
  install:
    runtime-versions:
      nodejs: 12
    commands:
      - source cicd/app_cicd.sh
      - npm_install

cicd/app_cicd.sh 在哪里

#!/bin/bash

function npm_install() {
    npm install
}

但是 CodeBuild 输出显示

[Container] 2021/05/23 01:55:32 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
[Container] 2021/05/23 01:55:32 Phase context status code:  Message: 
[Container] 2021/05/23 01:55:33 Entering phase INSTALL
[Container] 2021/05/23 01:55:33 Running command export CICD_ROOT=$(pwd)

[Container] 2021/05/23 01:55:33 Running command source cicd/app_cicd.sh

[Container] 2021/05/23 01:55:33 Running command npm_install
/codebuild/output/tmp/script.sh: line 4: npm_install: command not found

鉴于我已指定在 buildspec.yml 中使用 bash,并且我的 shell 脚本包含一个 shebang,我不确定哪里出了问题。这当然是一个人为的例子

最佳答案

npm_install 必须与您的 source 在同一行,否则它们将完全独立执行。所以你的 source 不会转移到第二个命令。

version: 0.2

env:
  shell: bash
phases:
  install:
    runtime-versions:
      nodejs: 12
    commands:
      - source cicd/app_cicd.sh && npm_install

关于amazon-web-services - 无法在 CodeBuild 中运行 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67655548/

相关文章:

caching - Cloudfront私有(private)内容+签名url架构

python - 使用 Boto 3 将文件从 AWS S3 传输到 SFTP

amazon-web-services - 如何计算 DynamoDB 表中的目标利用率?

linux - 有没有办法在 AWS linux 实例上执行 appium 测试用例?

mysql - docker-compose 无法启动 mysql :8 correctly

amazon-web-services - 将单个 Codebuild 项目部署到多个 ECS 容器

amazon-web-services - 过滤代码构建推送事件

amazon-web-services - 通过 CodeBuild 在 AWS Lambda 上安装 NLTK/WORDNET

amazon-web-services - 将环境变量从 AWS Codepipeline 传递到 CodeBuild

aws-codebuild - CodeBuild 无法运行 CDK 合成器