55

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.

Community
  • 1
  • 1
Крис
  • 1,190
  • 2
  • 11
  • 17

5 Answers5

123

You could also try adding the following line in your .travis.yml file:

before_script: cd project
iOSCowboy
  • 1,426
  • 2
  • 9
  • 9
48

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

Lxrd-AJ
  • 592
  • 7
  • 16
17

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
Odi
  • 6,916
  • 3
  • 34
  • 52
  • 2
    also needs a chmod on build.sh otherwise "permission denied" – Крис Feb 08 '13 at 20:31
  • what's the ++$TRAVIS_SCALA_VERSION for? Telling travis what version of scala to use? Not sure how to run this locally? – Toby Sep 17 '13 at 19:56
  • This is not relevant here, `build.sh` can contain anything. Make sure the `build.sh` runs locally. If this is the case, then you can use it to tell travis what to do when running a build job. – Odi Sep 18 '13 at 13:10
  • The answer from @iIOCowboy is clearly much better and has 10x the upvotes. – Daniele Dellafiore Oct 30 '18 at 15:43
1

Adding below on your .travis.yml file should do it:

before_script: cd <project_name>
script:
  - sbt compile
  - sbt test
SanjeevGhimire
  • 111
  • 2
  • 15
-2

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.

Mr-IDE
  • 7,051
  • 1
  • 53
  • 59