Conditions does not work in .travis.yml

I was trying to put a condition in install phase to run npm command based on a condition

if branch is master or demo, npm run build:${TRAVIS_BRANCH}
else npm run build

tried if and on branch command but this was not achieved.

- npm i travis-ci-cloudfront-invalidation --save-dev
- npm install
- npm run test:prod
- npm run build:${TRAVIS_BRANCH} => this line needs condition of branch