travis-ci/travis.rb(新しいタブで開きます)
主要言語: Ruby
Travis CI Client (CLI and Ruby library)
- star 数
- 1,593
- watcher 数
- 88
- fork 数
- 410
- issue 数
- 200
- 最終更新
- 2024/10/25
主要言語: Ruby
Travis CI Client (CLI and Ruby library)
The travis gem includes both a command line client and a Ruby library to interface with a Travis CI service using GitHub account. Both work with travis-ci.com or any custom Travis CI setup you might have. Check out the installation instructions to get it running in no time.
accounts - displays accounts and their subscription statusconsole - interactive shell; requires pryendpoint - displays or changes the API endpointlogin - authenticates against the API and stores the tokenmonitor - live monitor for what's going onraw - makes an (authenticated) API call and prints out the resultregenerate-token - regenerates the stored API tokenremove-token - deletes the stored API tokenreport - generates a report useful for filing issuesrepos - lists repositories the user has certain permissions onsync - triggers a new sync with GitHublint - display warnings for a .travis.ymltoken - outputs the secret API tokenwhatsup - lists most recent buildswhoami - outputs the current userbranches - displays the most recent build for each branchcache - lists or deletes repository cachescancel - cancels a job or builddisable - disables a projectenable - enables a projectencrypt - encrypts values for the .travis.ymlencrypt-file - encrypts a file and adds decryption steps to .travis.ymlenv - show or modify build environment variableshistory - displays a project's build historyinit - generates a .travis.yml and enables the projectlogs - streams test logsopen - opens a build or job in the browserpubkey - prints out a repository's public keyrequests - lists recent requestsrestart - restarts a build or jobsettings - access repository settingssetup - sets up an addon or deploy targetshow - displays a build or jobsshkey - checks, updates or deletes an SSH keystatus - checks status of the latest buildThere are three types of commands: Non-API Commands, General API Commands and Repository Commands. All commands take the form of travis COMMAND [ARGUMENTS] [OPTIONS]. You can get a list of commands by running help.
Every Travis command takes three global options:
-h, --help Display help
-i, --[no-]interactive be interactive and colorful
-E, --[no-]explode don't rescue exceptions
The --help option is equivalent to running travis help COMMAND.
The --interactive options determines whether to include additional information and colors in the output or not (except on Windows, we never display colors on Windows, sorry). If you don't set this option explicitly, you will run in interactive mode if you invoke the command directly in a shell and in non-interactive mode if you pipe it somewhere.
You probably want to use --explode if you are working on a patch for the Travis client, as it will give you the Ruby exception instead of a nice error message.
The help command will inform you about the arguments and options that the commands take, for instance:
$ travis help help Usage: travis help [command] [options] -h, --help Display help -i, --[no-]interactive be interactive and colorful -E, --[no-]explode don't rescue exceptions
Running help without a command name will give you a list of all available commands.
As you might have guessed, this command prints out the client's version.
API commands inherit all options from Non-API Commands.
Additionally, every API command understands the following options:
-e, --api-endpoint URL Travis API server to talk to
--com short-cut for --api-endpoint 'https://api.travis-ci.com/'
--pro short-cut for --api-endpoint 'https://api.travis-ci.com/'
--org short-cut for --api-endpoint 'https://api.travis-ci.org/'
-t, --token [ACCESS_TOKEN] access token to use
--debug show API requests
--adapter ADAPTER Faraday adapter to use for HTTP requests
You can supply an access token via --token if you want to make an authenticated call. If you don't have an access token stored for the API endpoint, it will remember it for subsequent requests. Keep in mind, this is not the "Travis token" used when setting up GitHub hooks (due to security). You probably don't have an access token handy right now. Don't worry, usually you won't use this option but instead just do a travis login.
The --debug option will print HTTP requests to STDERR. Like --explode, this is really helpful when contributing to this project.
There are many libraries out there to do HTTP requests in Ruby. You can switch amongst common ones with --adapter:
$ travis show --adapter net-http ... $ gem install excon ... $ travis show --adapter excon ...
The accounts command can be used to list all the accounts you can set up repositories for.
$ travis accounts rkh (Konstantin Haase): subscribed, 160 repositories sinatra (Sinatra): subscribed, 9 repositories rack (Official Rack repositories): subscribed, 3 repositories travis-ci (Travis CI): subscribed, 57 repositories ...
Provides an interactive shell via pry.
Running travis console gives you an interactive Ruby session with all the entities imported into global namespace.
This has advantages over irb -r travis, such as:
--debug if you are curious as to what's actually going on.$ travis console >> User.current => #<User: rkh> >> Repository.find('sinatra/sinatra') => #<Repository: sinatra/sinatra> >> _.last_build => #<Travis::Client::Build: sinatra/sinatra#360>
Interactive shell; requires `pry`.
Usage: travis console [OPTIONS]
-h, --help Display help
-i, --[no-]interactive be interactive and colorful
-E, --[no-]explode don't rescue exceptions
--skip-version-check don't check if travis client is up to date
--skip-completion-check don't check if auto-completion is set up
-e, --api-endpoint URL Travis API server to talk to
-I, --[no-]insecure do not verify SSL certificate of API endpoint
--pro short-cut for --api-endpoint 'https://api.travis-ci.com/'
--com short-cut for --api-endpoint 'https://api.travis-ci.com/'
--org short-cut for --api-endpoint 'https://api.travis-ci.org/'
--staging talks to staging system
-t, --token [ACCESS_TOKEN] access token to use
--debug show API requests
--debug-http show HTTP(S) exchange
-X, --enterprise [NAME] use enterprise setup (optionally takes name for multiple setups)
--adapter ADAPTER Faraday adapter to use for HTTP requests
-x, --eval LINE run line of ruby
Prints out the API endpoint you're talking to.
$ travis endpoint API endpoint: https://api.travis-ci.org/
Handy for using it when working with shell scripts:
$ curl "$(travis endpoint)/docs" > docs.htmlIt can also be used to set the default API endpoint used for General API Commands:
$ travis endpoint --com --set-default API endpoint: https://api.travis-ci.com/ (stored as default)
You can use --drop-default to remove the setting again:
$ travis endpoint --drop-default default API endpoint dropped (was https://api.travis-ci.com/)
The login command will, well, log you in. That way, all subsequent commands that run against the same endpoint will be authenticated.
$ travis login --pro --github-token ghp_******** Successfully logged in as rkh!
You need to use a GitHub token and supply it via --github-token. Travis CI will not store the token, though - after all, it already should have a valid token for you in the database.
NOTE: When creating a GitHub token, see GitHub Permissions used by travis-ci.com or GitHub Permissions used by travis-ci.org. The token permissions are dependent on use of travis-ci.com or travis-ci.org and not if they are public or private repositories.
A third option is for the really lazy: --auto. In this mode the client will try to find a GitHub token for you and just use that. This will only work if you have a global GitHub token stored in your .netrc. If you haven't heard of this, it's worth looking into in general. Again: Travis CI will not store that token.
This command makes Travis CI forget your access token.
$ travis logout --com Successfully logged out!
Usage: travis monitor [options]
-h, --help Display help
-i, --[no-]interactive be interactive and colorful
-E, --[no-]explode don't rescue exceptions
--skip-version-check don't check if travis client is up to date
-e, --api-endpoint URL Travis API server to talk to
--com short-cut for --api-endpoint 'https://api.travis-ci.com/'
--org short-cut for --api-endpoint 'https://api.travis-ci.org/'
-t, --token [ACCESS_TOKEN] access token to use
--debug show API requests
-X, --enterprise [NAME] use enterprise setup (optionally takes name for multiple setups)
-m, --my-repos Only monitor my own repositories
-r, --repo SLUG monitor given repository (can be used more than once)
-R, --store-repo SLUG like --repo, but remembers value for current directory
-n, --[no-]notify [TYPE] send out desktop notifications (optional type: osx, growl, libnotify)
-b, --builds only monitor builds, not jobs
-p, --push monitor push events
-P, --pull monitor pull request events
With monitor you can watch a live stream of what's going on:
$ travis monitor Monitoring travis-ci.org: 2013-08-05 01:22:40 questmaster/FATpRemote#45 started 2013-08-05 01:22:40 questmaster/FATpRemote#45.1 started 2013-08-05 01:22:41 grangier/python-goose#33.1 passed 2013-08-05 01:22:42 plataformatec/simple_form#666 passed ...
You can limit it to a single repository via --repo SLUG.
By default, you will receive events for both builds and jobs, you can limit it to builds only via --build (short -b):
$ travis monitor Monitoring travis-ci.org: 2013-08-05 01:22:40 questmaster/FATpRemote#45 started 2013-08-05 01:22:42 plataformatec/simple_form#666 passed ...
Similarly, you can limit it to builds/jobs for pull requests via --pull and for normal pushes via --push.
The monitor command can also send out desktop notifications:
$ travis monitor --com -n Monitoring travis-ci.com: ...
When monitoring specific repositories, notifications will be turned on by default. Disable with --no-notify.
This is really helpful both when working on this client and when exploring the Travis API. It will simply fire a request against the API endpoint, parse the output and pretty print it. Keep in mind that the client takes care of authentication for you:
$ travis raw /repos/travis-ci/travis.rb {"repo"=> {"id"=>409371, "slug"=>"travis-ci/travis.rb", "description"=>"Travis CI Client (CLI and Ruby library)", "last_build_id"=>4251410, "last_build_number"=>"77", "last_build_state"=>"passed", "last_build_duration"=>351, "last_build_language"=>nil, "last_build_started_at"=>"2013-01-19T18:00:49Z", "last_build_finished_at"=>"2013-01-19T18:02:17Z"}}
Use --json if you'd rather prefer the output to be JSON.
This command is used to regenerate the stored API token. New token will be stored in the config.
$ travis regenerate-token Successfully regenerated the token!
This command is used to remove the access token from the config, log out the user and disable the token.
$ travis remove-token Successfully removed the access token!
When inspecting a bug or reporting an issue, it can be handy to include a report about the system and configuration used for running a command.
$ travis report --com System Ruby: Ruby 2.0.0-p195 Operating System: Mac OS X 10.8.5 RubyGems: RubyGems 2.0.7 CLI Version: 1.5.8 Plugins: "travis-as-user", "travis-build", "travis-cli-pr" Auto-Completion: yes Last Version Check: 2013-11-02 16:25:03 +0100 Session API Endpoint: https://api.travis-ci.com/ Logged In: as "rkh" Verify SSL: yes Enterprise: no Endpoints pro: https://api.travis-ci.com/ (access token, current) org: https://api.travis-ci.org/ (access token) Last Exception An error occurred running `travis whoami --com`: Travis::Client::Error: access denied from ... For issues with the command line tool, please visit https://github.com/travis-ci/travis.rb/issues. For Travis CI in general, go to https://github.com/travis-ci/travis-ci/issues or email support@travis-ci.com.
This command can also list all known repos and the endpoint to use for them via the --known-repos option.
Lists repositories the user has certain permissions on.
Usage: travis repos [options]
-h, --help Display help
-i, --[no-]interactive be interactive and colorful
-E, --[no-]explode don't rescue exceptions
--skip-version-check don't check if travis client is up to date
--skip-completion-check don't check if auto-completion is set up
-e, --api-endpoint URL Travis API server to talk to
-I, --[no-]insecure do not verify SSL certificate of API endpoint
--com short-cut for --api-endpoint 'https://api.travis-ci.com/'
--org short-cut for --api-endpoint 'https://api.travis-ci.org/'
-t, --token [ACCESS_TOKEN] access token to use
--debug show API requests
-X, --enterprise [NAME] use enterprise setup (optionally takes name for multiple setups)
--adapter ADAPTER Faraday adapter to use for HTTP requests
-m, --match PATTERN only list repositories matching the given pattern (shell style)
-o, --owner LOGIN only list repos for a certain owner
-n, --name NAME only list repos with a given name
-a, --active only list active repositories
-A, --inactive only list inactive repositories
-d, --admin only list repos with (or without) admin access
-D, --no-admin only list repos without admin access
Lists repositories and displays whether these are active or not. Has a variety of options to filter repositories.
$ travis repos -m 'rkh/travis-*' rkh/travis-chat (active: yes, admin: yes, push: yes, pull: yes) Description: example app demoing travis-sso usage rkh/travis-encrypt (active: yes, admin: yes, push: yes, pull: yes) Description: proof of concept in browser encryption of travis settings rkh/travis-lite (active: no, admin: yes, push: yes, pull: yes) Description: Travis CI without the JavaScript rkh/travis-surveillance (active: no, admin: yes, push: yes, pull: yes) Description: Veille sur un projet.
In non-interactive mode, it will only output the repository slug, which goes well with xargs:
$ travis repos --active --owner travis-ci | xargs -I % travis disable -r % travis-ci/artifacts: disabled :( travis-ci/canary: disabled :( travis-ci/docs-travis-ci-com: disabled :( travis-ci/dpl: disabled :( travis-ci/gh: disabled :( ...
Usage: travis sync [options]
-h, --help Display help
-i, --[no-]interactive be interactive and colorful
-E, --[no-]explode don't rescue exceptions
-e, --api-endpoint URL Travis API server to talk to
--com short-cut for --api-endpoint 'https://api.travis-ci.com/'
--org short-cut for --api-endpoint 'https://api.travis-ci.org/'
-t, --token [ACCESS_TOKEN] access token to use
--debug show API requests
-c, --check only check the sync status
-b, --background will trigger sync but not block until sync is done
-f, --force will force sync, even if one is already running
Sometimes the info Travis CI has about users and repositories become out of date. If that should happen, you can manually trigger a sync:
$ travis sync synchronizing: ........... done
The command blocks until the synchronization is done. You can avoid that with --background:
$ travis sync --background starting synchronization
If you just want to know if your account is being synchronized right now, use --check:
$ travis sync --check rkh is currently syncing
This checks a .travis.yml file for any issues it might detect.
By default, it will read a file named .travis.yml in the current directory:
$ travis lint Warnings for .travis.yml: [x] your repository must be feature flagged for the os setting to be used
You can also give it a path to a different file:
$ travis lint example.yml ...
Or pipe the content into it:
$ echo "foo: bar" | travis lint Warnings for STDIN: [x] unexpected key foo, dropping [x] missing key language, defaulting to ruby
Like the status command, you can use -q to suppress any output, and -x to have it set the exit code to 1 if there are any warnings.
$ travis lint -qx || echo ".travis.yml does not validate"In order to use the Ruby library you will need to obtain an access token first. To do this simply run the travis login command. Once logged in you can check your token with travis token:
$ travis token Your access token is super-secret
You can use that token for instance with curl:
$ curl -H "Authorization: token $(travis token)" https://api.travis-ci.org/users/ {"login":"rkh","name":"Konstantin Haase","email":"konstantin.haase@gmail.com","gravatar_id":"5c2b452f6eea4a6d84c105ebd971d2a4","locale":"en","is_syncing":false,"synced_at":"2013-01-21T20:31:06Z"}
Note that if you just need it for looking at API payloads, that we also have the raw command.
It's just a tiny feature, but it allows you to take a look at repositories that have recently seen some action (ie the left hand sidebar on travis-ci.org):
$ travis whatsup mysociety/fixmystreet started: #154 eloquent/typhoon started: #228 Pajk/apipie-rails started: #84 qcubed/framework failed: #21 ...
If you only want to see what happened in your repositories, add the --my-repos flag (short: -m):
$ travis whatsup -m travis-ci/travis.rb passed: #169 rkh/dpl passed: #50 rubinius/rubinius passed: #3235 sinatra/sinatra errored: #619 rtomayko/tilt failed: #162 ruby-no-kai/rubykaigi2013 passed: #50 rack/rack passed: #519 ...
This command is useful to verify that you're in fact logged in:
$ travis whoami You are rkh (Konstantin Haase)
Again, like most other commands, goes well with shell scripting:
$ git clone "https://github.com/$(travis whoami)/some_project"-h, --help Display help
-i, --[no-]interactive be interactive and colorful
-E, --[no-]explode don't rescue exceptions
--skip-version-check don't check if travis client is up to date
--skip-completion-check don't check if auto-completion is set up
-e, --api-endpoint URL Travis API server to talk to
-I, --[no-]insecure do not verify SSL certificate of API endpoint
--com short-cut for --api-endpoint 'https://api.travis-ci.com/'
--org short-cut for --api-endpoint 'https://api.travis-ci.org/'
-t, --token [ACCESS_TOKEN] access token to use
--debug show API requests
-X, --enterprise [NAME] use enterprise setup (optionally takes name for multiple setups)
-r, --repo SLUG repository to use (will try to detect from current git clone)
-R, --store-repo SLUG like --repo, but remembers value for current directory
Repository commands have all the options General API Commands have.
Additionally, you can specify the Repository to talk to by providing --repo owner/name. However, if you invoke the command inside a clone of the project, the client will figure out this option on its own. Note that it uses the tracked git remote for the current branch (and defaults to 'origin' if no tracking is set) to do so. You can use --store-repo SLUG once to override it permanently.
It will also automatically pick travis-ci.com if it is a private project. You can of course override this decision with --com, --org or --api-endpoint URL
Displays the most recent build for each branch:
$ travis branches hh-add-warning-old-style: #35 passed Add a warning if old-style encrypt is being used hh-multiline-encrypt: #55 passed Merge branch 'master' into hh-multiline-encrypt rkh-show-logs-history: #72 passed regenerate gemspec rkh-debug: #75 passed what? hh-add-clear-cache-to-global-session: #135 passed Add clear_cache(!) to Travis::Namespace hh-annotations: #146 passed Initial annotation support hh-remove-newlines-from-encrypted-string: #148 errored Remove all whitespace from an encrypted string version-check: #157 passed check travis version for updates from time to time master: #163 passed add Repository#branches and Repository#branch(name)
For more fine grained control and older builds on a specific branch, see history.
Lists or deletes repository caches.
Usage: travis cache [options]
-h, --help Display help
-i, --[no-]interactive be interactive and colorful
-E, --[no-]explode don't rescue exceptions
--skip-version-check don't check if travis client is up to date
--skip-completion-check don't check if auto-completion is set up
-e, --api-endpoint URL Travis API server to talk to
-I, --[no-]insecure do not verify SSL certificate of API endpoint
--com short-cut for --api-endpoint 'https://api.travis-ci.com/'
--org short-cut for --api-endpoint 'https://api.travis-ci.org/'
-t, --token [ACCESS_TOKEN] access token to use
--debug show API requests
-X, --enterprise [NAME] use enterprise setup (optionally takes name for multiple setups)
-r, --repo SLUG repository to use (will try to detect from current git clone)
-R, --store-repo SLUG like --repo, but remembers value for current directory
-d, --delete delete listed caches
-b, --branch BRANCH only list/delete caches on given branch
-m, --match STRING only list/delete caches where slug matches given string
-f, --force do not ask user to confirm deleting the caches
Lists or deletes directory caches for a repository:
$ travis cache On branch master: cache--rvm-2.0.0--gemfile-Gemfile last modified: 2013-11-04 13:45:44 size: 62.21 MiB cache--rvm-ruby-head--gemfile-Gemfile last modified: 2013-11-04 13:46:55 size: 62.65 MiB On branch example: cache--rvm-2.0.0--gemfile-Gemfile last modified: 2013-11-04 13:45:44 size: 62.21 MiB Overall size of above caches: 187.07 MiB
You can filter by branch:
$ travis cache --branch master On branch master: cache--rvm-2.0.0--gemfile-Gemfile last modified: 2013-11-04 13:45:44 size: 62.21 MiB cache--rvm-ruby-head--gemfile-Gemfile last modified: 2013-11-04 13:46:55 size: 62.65 MiB Overall size of above caches: 124.86 MiB
And by matching against the slug:
$ travis cache --match 2.0.0 On branch master: cache--rvm-2.0.0--gemfile-Gemfile last modified: 2013-11-04 13:45:44 size: 62.21 MiB Overall size of above caches: 62.21 MiB
You can also use this command to delete caches:
$ travis cache -b example -m 2.0.0 --delete DANGER ZONE: Do you really want to delete all caches on branch example that match 2.0.0? |no| yes Deleted the following caches: On branch example: cache--rvm-2.0.0--gemfile-Gemfile last modified: 2013-11-04 13:45:44 size: 62.21 MiB Overall size of above caches: 62.21 MiB
This command will cancel the latest build:
$ travis cancel build #85 has been canceled
You can also cancel any build by giving a build number:
$ travis cancel 57 build #57 has been canceled
Or a single job:
$ travis cancel 57.1 job #57.1 has been canceled
If you want to turn off a repository temporarily or indefinitely, you can do so with the disable command:
$ travis disable travis-ci/travis.rb: disabled :(
With the enable command, you can easily activate a project on Travis CI:
$ travis enable travis-ci/travis.rb: enabled :)
It even works when enabling a repo Travis didn't know existed by triggering a sync:
$ travis enable -r rkh/test repository not known to Travis CI (or no access?) triggering sync: ............. done rkh/test: enabled
If you don't want the sync to be triggered, use --skip-sync.
Encrypts values for the .travis.yml.
Usage: travis encrypt [ARGS..] [OPTIONS]
-h, --help Display help
-i, --[no-]interactive be interactive and colorful
-E, --[no-]explode don't rescue exceptions
--skip-version-check don't check if travis client is up to date
--skip-completion-check don't check if auto-completion is set up
-e, --api-endpoint URL Travis API server to talk to
-I, --[no-]insecure do not verify SSL certificate of API endpoint
--pro short-cut for --api-endpoint 'https://api.travis-ci.com/'
--com short-cut for --api-endpoint 'https://api.travis-ci.com/'
--org short-cut for --api-endpoint 'https://api.travis-ci.org/'
--staging talks to staging system
-t, --token [ACCESS_TOKEN] access token to use
--debug show API requests
--debug-http show HTTP(S) exchange
-X, --enterprise [NAME] use enterprise setup (optionally takes name for multiple setups)
--adapter ADAPTER Faraday adapter to use for HTTP requests
-r, --repo SLUG repository to use (will try to detect from current git clone)
-R, --store-repo SLUG like --repo, but remembers value for current directory
-a, --add [KEY] adds it to .travis.yml under KEY (default: env.global)
-s, --[no-]split treat each line as a separate input
-p, --append don't override existing values, instead treat as list
-x, --override override existing value
This command is useful to encrypt environment variables or deploy keys for private dependencies.
$ travis encrypt FOO=bar Please add the following to your .travis.yml file: secure: "gSly+Kvzd5uSul15CVaEV91ALwsGSU7yJLHSK0vk+oqjmLm0jp05iiKfs08j\n/Wo0DG8l4O9WT0mCEnMoMBwX4GiK4mUmGdKt0R2/2IAea+M44kBoKsiRM7R3\n+62xEl0q9Wzt8Aw3GCDY4XnoCyirO49DpCH6a9JEAfILY/n6qF8=" Pro Tip™: You can add it automatically by running with --add.
For deploy keys, it is really handy to pipe them into the command:
$ cat id_rsa | travis encryptAnother use case for piping files into it: If you have a file with sensitive environment variables, like foreman's .env file, you can tell the client to encrypt every line separately via --split:
$ cat .env | travis encrypt --split Please add the following to your .travis.yml file: secure: "KmMdcwTWGubXVRu93/lY1NtyHxrjHK4TzCfemgwjsYzPcZuPmEA+pz+umQBN\n1ZhzUHZwDNsDd2VnBgYq27ZdcS2cRvtyI/IFuM/xJoRi0jpdTn/KsXR47zeE\nr2bFxRqrdY0fERVHSMkBiBrN/KV5T70js4Y6FydsWaQgXCg+WEU=" secure: "jAglFtDjncy4E3upL/RF0ZOcmJ2UMrqHFCLQwU8PBdurhTMBeTw+IO6cXx5z\nU5zqvPYo/ghZ8mMuUhvHiGDM6m6OlMP7+l10VTxH1CoVew2NcQvRdfK3P+4S\nZJ43Hyh/ZLCjft+JK0tBwoa3VbH2+ZTzkRZQjdg54bE16C7Mf1A=" Pro Tip: You can add it automatically by running with --add.
As suggested, the client can also add them to your .travis.yml for you:
$ travis encrypt FOO=bar --addThis will by default add it as global variables for every job. You can also add it as matrix entries by providing a key:
$ travis encrypt FOO=bar --add env.matrixThere are two ways the client can treat existing values:
env. and can be enforced with --append.env. and ca