Benoy John
Benoy John

Reputation: 81

How to use environnement variables inside a Robot framework script

I want to use the environnement variables provided by jenkins (like Build_Id) as part of my robot script.
For eg:

user = "abc" + Build_Id

This is so that I can match my variable/value to a particular build.

Is there a way to use the env variables inside a Robot script?

Upvotes: 1

Views: 9585

Answers (2)

Würgspaß
Würgspaß

Reputation: 4820

Yes you can pass command line options as described here.

So, if you start RF via Jenkins shell execution do something like this:

robot --variable Build_Id:$Build_Id path/to/tests/

If you start RF indirectly by calling a script or maven or ant build script, you have to pass the variables accordingly (here is an example for maven).

Upvotes: 2

Todor Minakov
Todor Minakov

Reputation: 20067

You can easily access environment variables, in fact they are available in the cases/keywords scope just like a normal user-defined variable

${my var}=    Set Variable    abc %{BUILD_ID}

Note the access char is %, not $ as is for the user variables.

You can also use the keyword Get Environment Variable from the OperatingSystem library, which allows to have a default value if the env variable is not present, or fail the case/keyword.

Upvotes: 3

Related Questions