Use TeamCity Parameters In The Robot Framework Console Output

946 views
Skip to first unread message

finspin

unread,
Feb 5, 2013, 9:52:33 AM2/5/13
to robotframe...@googlegroups.com
TeamCity (continous integration server) offers an option to pass some variables like build name, project name etc. to the command line when running Robot Framework tests. A typical usage would be to build RF outputdir path when, for example:

pybot --outputdir "C:\%env.TEAMCITY_PROJECT_NAME%\%env.TEAMCITY_BUILDCONF_NAME%\%env.BUILD_VCS_NUMBER%" C:\Tests\test.txt

That works great, RF will create the folders and subfolders based on the passed parameter values.

But would it be possible to capture these parameter values and use them in the console output after the tests are run by writing to stderr for example? Any ideas how this could be done?








finspin

unread,
Feb 5, 2013, 2:46:30 PM2/5/13
to robotframe...@googlegroups.com
I figured out how to do it. There might be an easier way but here goes my solution. This is a simplified version but all necessary steps are here:

1. Create a custom keyword

def output_build_details(self, build_number):
        print >> sys.stderr.write('This is a build number: ' + build_number)


2. Call the custom keyword in the test case file

*** Settings ***
Suite Teardown      Output Build Details   ${BUILD_NUMBER}


3. When initiating the RF test from TeamCity, store the build number in a variable

pybot --variable BUILD_NUMBER:%env.BUILD_VCS_NUMBER% C:\Tests\test.txt


That way you can output TeamCity parameters' values in the console.

It would be more convenient to use the variable ${BUILD_NUMBER} right in the custom keyword function and leave out the step #2 completely out. Is this possible?


Kevin O.

unread,
Feb 5, 2013, 10:46:19 PM2/5/13
to robotframe...@googlegroups.com
There's a way to access that variable from RF and log to the console (depends on OperatingSystem library). There's no option to log to the console in BuiltIn, but you can do it like this:
Log Build Number
    ${build number}=    OperatingSystem.Get Environment Variable    BUILD_VCS_NUMBER    NON_TC_BUILD
    ${logger}=    Evaluate    robot.api.logger    robot
    Call Method    ${logger}    console    \nThis is build number: ${build number}

In Python you can do something like this:

import os
from robot.api import logger
...

    def output_build_details(self):
        build_number = os.environ.get('BUILD_VCS_NUMBER', 'NON_TC_BUILD')
        logger.console('\nThis is a build number: ' + build_number)
Reply all
Reply to author
Forward
0 new messages