Travis CI to modify same branch (may have to use git stash pop)

I want to use Travis to run a bash script and commit the result back to the same branch on github with a git stash pop (The script generates a markdown table of contents, which is complex but could be anything really within the MD). Obviously this causes an issue as travis will then see a new commit and run again ad infinitum. I tried to use

if: sender != "Travis CI"

Also used

git stash pop

there has better way to achieve what I need w/o using GSP?

There might cleaner ways of doing it especially one without using git stash pop or using git stash at all.

One way that comes off the top of my head is this piece documentation:

According to this, you can simply add a “tag” or specific string to your commit message in order to avoid Travis building it. This is a fairly common use practice on bigger builds, let’s say something with openjdk8 and it’s a build that could use a lot of resources.

Simply add ci skip or skip ci to your commit message and Travis will ignore it. These will have to have read/write, if you’re not familiar I’ve made this table for you so you can get it right on the first time (hopefully):

     owner read (r)
     owner write (w)
     owner execute (x)
        group read (r)
        group write (w)
        group execute (x)
           public read (r)
           public write (w)
           public execute (x)

So make it executable via chmod, and our function in push.sh will become the following:

commit_website_files() {
  git checkout -b gh-pages
  git add . *.html
  git commit --message "[skip cp] Travis build: $TRAVIS_BUILD_NUMBER"
}

You can still git push that branch that isn’t being watched by Travis. This can get complex when you start using remotes. For example, it could end up looking like this after all said and done:

git config --list | grep fetch
remote.origin.fetch=+refs/heads/master:refs/remotes/origin/master

You can run:

travis history --limit 100 --com -r travis-ci/travis-api

While logged in, make sure your limit does not exceed 100. You should get similar results to my screenshot I just took to give you an actual visual:

This can get complex, if you need extra help - please feel free DM me as you sometimes do, or post back publicly, I’d prefer publicly so everyone in the community benefits from our back and forth.

Good luck, and happy building!

2 Likes
Imprint