I’m trying to run a specific bash script using after_success
. The reason is that I want to push changes to docker hub but do it only when the master branch is updated, not when the PR passes the tests.
This is a super simplified version in order to keep it as short as possible.
The folder structure is like this
|-- scripts
|-- dockerhub.sh
|-- index.js
|-- Dockerfile
|-- package.json
|-- .travis.yml
.travis.yml
sudo: required
services:
- docker
script:
- npm run test
after_success:
- ./scripts/dockerhub.sh
dockerhub.sh
#!/bin/sh
if [[ "$TRAVIS_BRANCH" != "master" ]]; then
echo "We're not on the master branch!!."
# This will analyze the current branch and react accordingly
exit 0
fi
if [[ "$TRAVIS_BRANCH" == "master" ]]; then
echo "We ARE on the master branch!!!."
# This will analyze the current branch and react accordingly
exit 0
fi
In the build process I see this:
./scripts/dockerhub.sh: 3: ./scripts/dockerhub.sh: [[: not found
./scripts/dockerhub.sh: 9: ./scripts/dockerhub.sh: [[: not found
If I change the dockerhub.sh
to this:
#!/bin/sh
if [[ "$TRAVIS_BRANCH" != "master" ]]; then
echo "We're not on the master branch!!."
# This will analyze the current branch TheDFury and react accordingly
exit 0
fi
I still get the first error ./scripts/dockerhub.sh: 3: ./scripts/dockerhub.sh: [[: not found
This is the latest build:
https://travis-ci.com/github/rhernandog/dockerhub-travis-push/builds/166637696