How to Execute Git Push in Travis CI

Background Travis CI is generally used for automating tests without needing to update the repository with the test outputs. This article explains how to automatically commit the results from Travis CI. Process The basic process references this gist. Below is the .travis.yml from the gist. language: ruby rvm: - 2.0.0 env: global: - USER="username" - EMAIL="[email protected]" - REPO="name of target repo" - FILES="README.md foo.txt bar.txt" - GH_REPO="github.com/${USER}/${REPO}.git" - secure: "put travis gem output here => http://docs.travis-ci.com/user/encryption-keys/" script: - ruby test.rb after_success: - MESSAGE=$(git log --format=%B -n 1 $TRAVIS_COMMIT) - git clone git://${GH_REPO} - mv -f ${FILES} ${REPO} - cd ${REPO} - git remote - git config user.email ${EMAIL} - git config user.name ${USER} - git add ${FILES} - git commit -m "${MESSAGE}" - git push "https://${GH_TOKEN}@${GH_REPO}" master > /dev/null 2>&1 Note here that MESSAGE should be quoted when committing, which the original gist did not include. ...

October 16, 2017 · 4 min · 659 words · Jack Yu