Can I upload files from the working TravisCI file system to a local drive?
I am trying to run a visual diff using PhantomJS on Travis-CI. The test failed with the following error :
test failed
0.188123 distortion
Ref: /tmp/tmpaVuhik/tmpg6uSXl/ref_resized
Run: /tmp/tmpaVuhik/tmpg6uSXl/screenshot.png
Diff: /tmp/tmpaVuhik/tmpg6uSXl/diff.png
The visual differences helped in delivering the expected screenshot, the actual screenshot, and the perceptual difference in PNG files on a local drive on the Travis desktop. What would be great if I could see them!
Can I upload files from Travis scratch disk to local disk?
source to share
You can use travis-artifacts to load files generated by running tests. It currently only supports uploading to Amazon S3.
source to share
You can scp artifacts to your own server. With commercial travis, they provide a private key that you can use to identify the build (add the corresponding public key to authorized_keys on the target server). With travis-ci.org, you can do this much longer.
(Read everything before you make a reservation before you start.)
-
Generate a public key pair. You will use this to allow Travis build to authenticate and give it access to your server.
ssh-keygen -f build_id_rsa -P ''
-
Add the public key to authorized_keys on the target server.
$ scp build_id_rsa.pub user@server:. user@sever password: build_id_rsa.pub $ ssh user@server [...] $ mkdir .ssh $ cat build_id_rsa.pub >>.ssh/authorized_keys $ exit
-
Create known_hosts by going into the ad hoc known_hosts file. When asked if you are happy with your fingerprint, enter yes
$ ssh -i build_id_rsa -oUserKnownHostsFile=build_known_hosts -oPasswordAuthentication=no user@server The authenticity of host [...] can't be established. ECDSA key fingerprint is [...] Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'server,[...]' (ECDSA) to the list of known hosts. Welcome to [...] user@server:~$ exit logout Connection to server closed.
-
If you repeat the same command, you can check that we have configured the keys and known_host correctly. This time, he should log in without any questions, no confirmation, no password.
$ ssh -i build_id_rsa -oUserKnownHostsFile=build_known_hosts -oPasswordAuthentication=no user@server Welcome to [...] user@server:~$ exit logout Connection to server closed.
-
Now you need to set up your build. You cannot directly use the private key as this will allow anyone to log into the target server, so we will encrypt the private key. You can use something like
$ openssl enc -aes-256-cbc -salt -in build_id_rsa -out build_id_rsa.enc enter aes-256-cbc encryption password: Verifying - enter aes-256-cbc encryption password:
-
Add build_id_rsa.enc and build_known_hosts to your project
-
Add symmetric password to .travis.yml using
travis encrypt 'PASS=yoursymmetricpassword' --add
so you should get
env: global: - secure: [...]
added to your .travis.yml
-
Now modify your .travis.yml to load artifacts.
before_script: - openssl aes-256-cbc -d -pass env:PASS -in build_id_rsa.enc -out build_id_rsa ; chmod 600 build_id_rsa script: - if [[ "$TRAVIS_PULL_REQUEST" == 'false' && "$TRAVIS_BRANCH" == 'master' ]] ; then your_build && scp -q -i build_id_rsa -oPasswordAuthentication=no -oUserKnownHostsFile=build_known_hosts artefact user@server:path/ ; else ; your_build ; fi after_script: - rm -rf build_id_rsa
Caveats: Make sure you understand all the steps, as I probably made some typos and the mechanism is not super secure: Enables writing the private key to the Travis VM filesystem at build time. There are many ways in which something can go wrong, and this file can be opened giving access to your server.
source to share