Skip to content

This is travis helper to run particular work only once in matrix

License

Notifications You must be signed in to change notification settings

dmakhno/travis_after_all

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

travis_after_all

Build Status

This is a Travis CI helper to run particular work only once in matrix.

This is a workaround for: travis-ci/travis-ci#929

Dependencies

This script assumes an environment variable called GITHUB_TOKEN is always available for Travis CI builds. This token will be used for retrieving a temporary Travis token for the LEADER job to poll Travis about the state of the other jobs.

Read more about creating a suitable GitHub token here.

Once you have a suitable token available, you can make sure it ends up encrypted in your .travis.yml file by doing:

gem install travis
travis encrypt GITHUB_TOKEN="github-token" --add

After this step you will find new lines in your Travis CI config:

env:
  global:
    secure: "encrypted-github-token"

Usage

The main goal of this script to have a single publish when a build has several jobs. Currently the first job is a leader, meaning a node that will do the publishing.

An example .travis.yml shows how to ensure that all_succeeded or all_failed:

#...
script:
  - curl -Lo travis_after_all.py https://raw.github.com/dmakhno/travis_after_all/master/travis_after_all.py
after_success:
  - python travis_after_all.py https://api.travis-ci.com
  - export $(cat .to_export_back)
  - |
      if [ "$BUILD_LEADER" = "YES" ]; then
        if [ "$BUILD_AGGREGATE_STATUS" = "others_succeeded" ]; then
          echo "All jobs succeeded! PUBLISHING..."
        else
          echo "Some jobs failed"
        fi
      fi
after_failure:
  - python travis_after_all.py https://api.travis-ci.com
  - export $(cat .to_export_back)
  - |
      if [ "$BUILD_LEADER" = "YES" ]; then
        if [ "$BUILD_AGGREGATE_STATUS" = "others_failed" ]; then
          echo "All jobs failed"
        else
          echo "Some jobs failed"
        fi
      fi
after_script:
  - echo leader=$BUILD_LEADER status=$BUILD_AGGREGATE_STATUS

Limitations/Todo

  • If other jobs will start late, can be global build timeout (think of passing leader role to others, for example who started last is the leader).
  • More flexible leader definition (in matrix not all jobs can publish).
  • Have several leaders, according to flavours (e.g. if in matrix slices responsible for platform).

About

This is travis helper to run particular work only once in matrix

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages