Run a deployment script only once in the Travis test matrix.
On Travis builds running multiple jobs (to test with multiple Node versions and/or OSs), run some code from the after_success
phase only once, after all other jobs have completed successfully.
Your code will run only on the job with the highest node version (i.e. the build leader).
npm install --save travis-deploy-once
const deployOnce = require('travis-deploy-once'); try { const result = await deployOnce({travisOpts: {pro: true}, GH_TOKEN: 'xxxxxx', BUILD_LEADER_ID: 1}); } catch (err) { // something went wrong, and err will tell you what } if (result === true) deployMyThing(); if (result === false) console.log('Some job(s) failed'); if (result === null) console.log('Did not run as the build leader');
Returns a Promise
that resolves to:
true
if the current Travis job is the build leader, the currentscript
phase is successful and all other job have completed successfully. => Your code can safely run.false
if at least one Travis job failed. => Your code should not run.null
if the current Travis job is not the build leader. => Your code should not run, and will be executed on the build leader.
Throws an Error
if:
- It doesn't run on Travis.
- The Github authentication token is missing.
- The Github authentication token is not authorized with Travis.
- It doesn't run on after_success step.
Type: Object
Type: String
Default: process.env.GH_TOKEN
or process.env.GITHUB_TOKEN
GitHub OAuth token.
Type: Number
Default: process.env.BUILD_LEADER_ID
Defined which Travis job will run the script (build leader). If not defined the build leader will be the Travis job running on the highest Node version.
Type: Object
Type: Boolean
Default: false
true
to use Travis Pro, false
to use Travis for Open Source.
Type: String
Travis Enterprise URL. If defined, the pro option will be ignored.
Note: This is the URL of the API endpoint, for example https://travis.example.com/api
.