It's all about the answers!

Ask a question

Perl API - environments variables


shiran shem tov (1211114) | asked Oct 17 '10, 7:55 a.m.
Hi,

I have a perl script that works with the Build Forge through the API.

I want to check if a value exist in one of my environment variable, and if not to add it.

I tried to look in the documentation, but i can't find it.

Please help,
Thanks
shiran

11 answers



permanent link
Bryan Miller - Integration Developer (4493531) | answered Dec 08 '10, 1:25 p.m.
Hi,

With your information, I've modified the script. It worked for me.


use strict;

use BuildForge::Services;

my $host = 'localhost';
my $user = 'root';
my $password = 'root';
my $envName = 'TEST_ENV_1';
my $varName = 'TEST_VAR_1';
my $optionName = 'Model Office';
my $optionValue = 'MO';

my $conn = new BuildForge::Services::Connection($host);
my $token = $conn->authUser($user, $password);

my $env = BuildForge::Services::DBO::Environment->findByName($conn, $envName);
die('Could not find env ' . $envName) unless defined($env);

my $envEntry = $env->getEntry($varName);
die('Could not find env entry with name ' . $varName) unless defined($envEntry);

die('Env entry is not a pull down variable type entry') unless ($envEntry->getVariableType() eq 'PULLDOWN');

$envEntry = BuildForge::Services::DBO::EnvironmentEntry->findByUuid($conn, $envEntry->getUuid());
die('Could not find env entry by UUID') unless defined($envEntry);

my $envEntryOption = $envEntry->getOption($optionName);

if (!defined($envEntryOption)) {
$envEntryOption = new BuildForge::Services::DBO::EnvironmentEntryOption($conn);
$envEntryOption->setName($optionName);
$envEntryOption->setValue($optionValue);
$envEntryOption = $envEntryOption->update();
$envEntry->addOption($envEntryOption);
$envEntry = $envEntry->update();
print "Added env entry option named " . $optionName . " with value of " . $optionValue . " to env entry named " . $envEntry->getName() . ".\n";
} else {
print "The option " . $optionName . " already exists for variable " . $varName . " and contains value of " . $envEntryOption->getValue() . ".\n";
}

$conn->logout();
$conn->close();


Hi,
every time i run this line:
my $env = BuildForge::Services::DBO::Environment->findByName
($conn, $envName);

I get Could not find env message, i tried with few of my environment but it happened with all of them, do you know what can be the problem?
I have installed a new BF server so the environment were imported to the new server.

Thanks,
shiran

Check to see if you can manually view the contents of the environment from the console. The relocation process may have missed the environments or the names may have changed slightly.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.