Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I customize / override the "git clone" step in Travis CI?

Tags:

travis-ci

On the install step, Travis CI clones the repo, which looks similar to this:

git clone --depth=50 --branch=master https://github.com/user/repo.git user/repo

How can I customize / override this?


Background: I am using tag based deploys. The way Travis checks out tagged builds (--branch=<tagname>), the git repository is in a detached state without access to branches. However, for deployment I need to know on which branch I am. My solution is to do a "normal" clone and then switch to the tagged commit.

like image 993
ericteubert Avatar asked Sep 15 '15 08:09

ericteubert


People also ask

Which of the following file is used to configure the Travis CI?

Configuration. Travis CI is configured by adding a file named . travis. yml , which is a YAML format text file, to the root directory of the repository.

Which of the following techniques custom SSH keys are only available to private repositories?

Custom SSH keys are currently only available for private repositories on travis-ci.com. You can add SSH keys to user accounts on GitHub. Most users have probably already done this to be able to clone the repositories locally. This way, a single key can access multiple repositories.

Which of the following build automation tool can be used with Travis CI?

Travis CI supports parallel testing. It can also be integrated with tools like Slack, HipChat, Email, etc. and get notifications if the build is unsuccessful. Developers can speed up their test suites by executing multiple builds in parallel, across different virtual machines.


2 Answers

You can clone the repository again in the install step. That way you clone the repository twice, but it seems to work.

# .travis.yml install:   - git clone https://github.com/$TRAVIS_REPO_SLUG.git $TRAVIS_REPO_SLUG   - cd $TRAVIS_REPO_SLUG   - git checkout -qf $TRAVIS_COMMIT 
like image 63
ericteubert Avatar answered Sep 28 '22 07:09

ericteubert


Per the Travis docs you can add the following to your .travis.yml to remove the --depth flag:

git:   depth: false 

As --depth implies --single-branch, removing this flag means that all branches will be checked out, which isn't the default behaviour.

like image 40
jonrsharpe Avatar answered Sep 28 '22 07:09

jonrsharpe