egimaben
egimaben

Reputation: 823

Push into master branch from Travis CI

I am switching from Jenkins to Travis CI.

In Jenkins, I did not have to write a script to push my Java/android library to Git master branch.

With Travis, all my research shows that I need to write a custom bash script to execute in after_success.

This is my deploy.sh:

#!/bin/bash
rev=$(git rev-parse --short HEAD)
git config user.name "uname"
git config user.password "password"
git add .
git commit -m "travis commit at ${rev}"
git push origin master

and my .travis.yml:

branches:
  only:
    - development

language: android
sudo: false

android:
  components:
    - build-tools-22.0.1
    - android-22

script:
  - cd appdir
  - ./gradlew test


after_success:
  - cd ..
  - ./deploy.sh

before_cache:
  - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
cache:
  directories:
    - $HOME/.gradle/caches/
    - $HOME/.gradle/wrapper/

Under the script section, I cd from root dir to my appdir and run tests from there (successfully) then in the after_success section, I cd back into root where my deploy.sh is located and call it.

My Travis CI console shows everything is successful but I don't see any changes in my master branch.

Am I doing anything wrong?

Thanks.

Upvotes: 0

Views: 1118

Answers (1)

griffio
griffio

Reputation: 244

My experience is that Git doesn't appear know the branch your build is using and you want to push the current HEAD that has the additional commit.

In Travis CI you may have a log message just showing 'Everything up-to-date' as Git is pushing the same master branch.

You could change your script to add HEAD.

#!/bin/bash
rev=$(git rev-parse --short HEAD)
git config user.name "uname"
git config user.password "password"
git add .
git commit -m "committed at ${rev}"
git push origin HEAD:master

This is a similar answer that explains :- git-pushing-to-github-origin-master-does-nothing.

Upvotes: 2

Related Questions