How to specify a build folder in Travis?
Travis CiTravis Ci Problem Overview
I have a github repository user/repo
but the real project is in a subfolder user/repo/project/build.sbt
What should I write in the .travis.yml
to make Travis ignore the top folder and work only in the project folder?
Inspired by this I tried the following which didn't work:
env:
global:
- REPO="user/repo"
- CI_HOME=`pwd`/$REPO
script: sh -c 'cd $CI_HOME/project' && sbt ++$TRAVIS_SCALA_VERSION package
Error log:
$ sh -c 'cd $CI_HOME/project' && sbt ++$TRAVIS_SCALA_VERSION package
Detected sbt version 0.12.2-RC1
/home/travis/build/user/repo doesn't appear to be an sbt project.
Ideally there should be a way to specify the build folder but let Travis handle the build command.
Travis Ci Solutions
Solution 1 - Travis Ci
You could also try adding the following line in your .travis.yml file:
before_script: cd project
Solution 2 - Travis Ci
I tried using this in my travis.yml file but didnt work
before_script: cd project
Then i tried this
before_install: cd project
And that worked
Solution 3 - Travis Ci
Just write a shell script and use this to build your project. Make sure it works locally. Something like this should do the trick:
build.sh
:
#!/bin/sh
cd $TRAVIS_BUILD_DIR/project
sbt ++$TRAVIS_SCALA_VERSION package
.travis.yml
:
script: build.sh
Solution 4 - Travis Ci
Adding below on your .travis.yml file should do it:
before_script: cd <project_name>
script:
- sbt compile
- sbt test
Solution 5 - Travis Ci
In your yml file, add a "cd sub-folder
" step, before you run the build command:
default: - step: script: - cd project - sbt ++$TRAVIS_SCALA_VERSION package
Example for gradle projects:
default: - step: script: - cd project - chmod +x gradlew - ./gradlew assembleDebug
This will fix an error like "chmod: cannot access 'gradlew': No such file or directory"
, if the gradlew
file is in a different folder to the git root.
It will also work in other build systems that use yml files, like bitbucket-pipelines.yml.