gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 07:37:39 25 4
gpt4 key购买 nike

我有以下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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com