Robot on Travis – uploading results to S3

This is a walkthrough of how one could upload to Amazon S3 screenshots and other output files produced by Robot framework ran in a Travis CI build. The reason why we want to do this is to be able to inspect what Robot sees and have more information when a test fails. It’s written with some things specific to Plone development, nevertheless it should still be useful for any other framework/language supported by Travis.

Preparing Amazon S3

  1. Go to http://aws.amazon.com/ and sign-up & login.
  2. Go to http://aws.amazon.com/s3/ and click “Sign Up Now” to enable Amazon S3 for your account.
  3. Go to https://console.aws.amazon.com/s3/home and click “Create Bucket” named “my-travis-builds” or something similar. Travis will upload screenshots inside this bucket.
  4. Go to https://console.aws.amazon.com/iam/home, click “Users” in the left navigation sidebar and then click “Create New Users” button. Enter “travis” as a username and keep the “Generate an access key for each User” checked. This is the user that Travis CI will use to upload files to your Amazon S3 account. When your user is created click the “Download credentials” — we’ll need them later.
  5. Now click on the “travis” user, select the “Permissions” tab and click “Attach User Policy”. Select “Custom Policy” and click “Select”. Enter “travis-upload-only” or similar as the Policy Name and paste the following into the Policy Document field:
    {
      "Statement": [
        {
          "Action": [
            "s3:ListObject",
            "s3:PutObject"
          ],
          "Effect": "Allow",
          "Resource": [
            "arn:aws:s3:::my-travis-builds"
          ]
        },
        {
          "Action": [
            "s3:ListObject",
            "s3:PutObject"
          ],
          "Effect": "Allow",
          "Resource": [
            "arn:aws:s3:::my-travis-builds/*"
          ]
        },
        {
          "Action": [
            "s3:ListAllMyBuckets"
          ],
          "Effect": "Allow",
          "Resource": [
            "arn:aws:s3:::*"
          ]
        }
      ]
    }
    

    This policy gives the “travis” user minimal required permissions to upload files into the “my-travis-builds” bucket with s3cmd. We are now ready to start uploading!

 

Preparing s3cmd

Travis will later use s3cmd to upload files to Amazon S3. Before moving on to configuring Travis, you need to add a “.s3cfg” file to your repository. This file configures s3cmd with access credentials. Open the “credentials.csv” you downloaded earlier when creating a “travis” user through Amazon IAM and paste access and secret keys into “.s3cfg”. Commit & push.

[default]
access_key = INSERT ACCESS KEY FROM CREDENTIALS.CSV
secret_key = INSERT SECRET KEY FROM CREDENTIALS.CSV

 

Configuring Travis CI

I’m assuming you already have “.travis.yml” in your repository and you are already running builds on Travis CI. If this is not the case, check out the following URLs to get you up to speed:

Then, if you haven’t yet, add the following two lines to “before_script” in your .travis.yml file, to enable the virtual X frame buffer, so Robot tests have something to run against.

before_script:
  - "export DISPLAY=:99.0"
  - "sh -e /etc/init.d/xvfb start"

Moving on, you’ll need “s3cmd” installed on your Travis VM, so add the following to your .travis.yml.

install:
  - sudo apt-get install s3cmd

Now, as the last step, add the following line to “after_script” in your .travis.yml file. This uses the s3cmd installed above and the .s3cfg added in the previous section to upload screenshots created by Robot to the “my-travis-builds” bucket on S3, inside the #<travis_job_id> folder.

after_script:
  - s3cmd put --acl-private --guess-mime-type --config=.s3cfg selenium-screenshot* s3://my-travis-builds/#$TRAVIS_JOB_ID/

Now go back to https://console.aws.amazon.com/s3/home and bask in the glory of having Robot test screenshots in your S3 bucket!

Robot screenshots