3

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?

lolsob
  • 51
  • 9
  • Welcome to SO! Could you please append your full buildspec file to your post? If you are trying to use multiline commands, please make sure it is formatted as shown [here](https://github.com/aws-samples/aws-codebuild-multiple-buildspec/issues/2). – berenbums Jul 17 '20 at 10:50

1 Answers1

0

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

This answer helped me.

Rufi
  • 2,529
  • 1
  • 20
  • 41