4

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

1 Answer 1

5

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
Sign up to request clarification or add additional context in comments.

1 Comment

Do you know if it is possible to keep the state between list items?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.