I have the following buildspec.yml
version: 0.2
env:
  shell: bash
phases:
  install:
    runtime-versions:
      nodejs: 12
    commands:
      - source cicd/app_cicd.sh
      - npm_install
Where cicd/app_cicd.sh is
#!/bin/bash
function npm_install() {
    npm install
}
But the CodeBuild output shows
[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
Given that I've specified to use bash in the buildspec.yml and my shell script includes a shebang, I'm not sure what's wrong. This is of course a contrived example
npm_install must be in same line as your source, otherwise they are executed fully independently. So your source does not carry over to the second command.
version: 0.2
env:
  shell: bash
phases:
  install:
    runtime-versions:
      nodejs: 12
    commands:
      - source cicd/app_cicd.sh && npm_install
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With