Skip to content

🔂 Script to help execute code only once in a Travis CI build matrix

License

Notifications You must be signed in to change notification settings

redguava/travis-after-all

 
 

Repository files navigation

travis-after-all

Build Status devDependency Status

travis-after-all is a script that can help you execute code only once in a build matrix based on whether the build has succeeded or failed.

Or to put it in another way, travis-after-all is basically a temporary workaround for: travis-ci/travis-ci#929.

Usage

[1] Include the command that executes the travis-after-all script inside after_script (or inside of a script that is included inside after_script).

[2] Based on the (exit) code returned by travis-after-all, run your custom code.

See examples.

--

Terminology:

  • A job passed if either the tests passed, or the tests failed, but the job was allowed to fail.

  • A build succeeded if all jobs passed and there is at least one job whose tests passed.

  • A build failed if there is at least one job that didn't pass, or if all jobs passed, but for all of them the tests failed.

--

Meaning of (exit) codes:

  • 0 - is returned to the job that was assigned to run the code if the build succeeded

  • 1 - is returned to the job that was assigned to run the code if the build failed

  • 2 - is returned to the jobs that where not assigned to do anything

  • 3 - is returned if something went wrong (e.g.: travis-after-all failed to connect to Travis CI's API)

Usage examples

This section gives two examples of how your Travis job can obtain and use travis-after-all.

Obtaining via npm

Install travis-after-all as a devDependency.

npm install --save-dev travis-after-all

Then, in your .travis.yml file, add:

# ...

after_script:
  - |

      declare exitCode;


      # -- [1] -------------------------------------------------------

      $(npm bin)/travis-after-all
      exitCode=$?


      # -- [2] -------------------------------------------------------

      if [ $exitCode -eq 0 ]; then
        # Here goes the code that needs to be executed if the build succeeded
      fi

      if [ $exitCode -eq 1 ]; then
        # Here goes the code that needs to be executed if the build failed
      fi


# ...

You can also run travis-after-all from within your node script, e.g.:

var travisAfterAll = require('travis-after-all');

function callback(code, error) {

    if ( error !== undefined ) {
       // ...
    } else {

        if ( code === 0 ) {
          // Here goes the code that needs to be executed if the build succeeded
        } else if ( code === 1) {
          // Here goes the code that needs to be executed if the build failed
        }

    }

}

travisAfterAll(callback);

Obtaining via curl

⚠️ If you're using this method, please try to keep up with the releases and update the version number once a new version is released.

In your .travis.yml file add:

# ...

after_script:
  - |

      declare exitCode


      # -- [1] -------------------------------------------------------

      curl -sSL https://raw.githubusercontent.com/alrra/travis-after-all/1.4.4/lib/travis-after-all.js | node
      exitCode=$?


      # -- [2] -------------------------------------------------------

      if [ $exitCode -eq 0 ]; then
        # Here goes the code that needs to be executed if the build succeeded
      fi

      if [ $exitCode -eq 1 ]; then
        # Here goes the code that needs to be executed if the build failed
      fi

# ...

Note: travis-after-all is written in JavaScript, however, since Travis includes the Node runtime by default, it can be used no matter what build environment you have.

License

The code is available under the MIT license.

About

🔂 Script to help execute code only once in a Travis CI build matrix

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 93.5%
  • Shell 6.5%