Push to git master branch from Travis CI

不打扰是莪最后的温柔 提交于 2019-12-12 04:10:05

问题


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 console shows everything is successful but I don't see any change in my master branch.
What am I doing wrong?


回答1:


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.



来源:https://stackoverflow.com/questions/36915499/push-to-git-master-branch-from-travis-ci

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!