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?

1
  • 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. Commented Jul 17, 2020 at 10:50

1 Answer 1

0

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

This answer helped me.

Sign up to request clarification or add additional context in comments.

Comments

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.