Conditional statement in CodeBuild commands - JSON

Viewed 1155

I have a file that builds our CodeBuild commands and I need to check to see if an environment variable exists before doing an action. Some of the packages it builds this file have an environment variable PACKAGE_PATH, due to being a monorepo and some don't. These are built into JSON, not YAML, which is something I can't change at this point.

I keep getting the error:

[Container] 2020/07/10 21:10:13 Running command if [ -n ${PACKAGE_PATH} ]; then
/codebuild/output/tmp/script.sh: line 22: syntax error: unexpected end of file

The lines I'm trying to run are:

if [ -n ${PACKAGE_PATH} ]; then
    cd ${PACKAGE_PATH}
fi

Is this a case of incorrect syntax or is there an issue with doing a conditional statement like this in JSON build commands? I can't really find documentation on this. If it is a syntax issue, can someone please let me know how to correct it?

1 Answers

You need to add ; after cd ${PACKAGE_PATH}.

This answer helped me.

Related