It's all about the answers!

Ask a question

execute Build forge project from command line


shiran shem tov (1211114) | asked Jul 04 '10, 9:00 a.m.
Hi all,

I want to execute a build forge project from command line.
I need to run the command from a perl script.

I found a tool called bftool, but this tool is from version 7.0.2, i wanted to know if there is something newer.

My build forge version is 7.1.1.4.

Thanks,
Shiran

20 answers



permanent link
shiran shem tov (1211114) | answered Jul 20 '10, 9:44 a.m.
hi bju,

I am trying to set a user email in the perl API.

when i write the email in the code

$user='builder';
$user = BuildForge::Services::DBO::User->findByLogin($conn, 'builder');
$user->setEmail('user@company.com");
$user->update();

It worked, but when i tried to set the email with a variable it doesn't work:
$user->setEmail($mail);

When i print to the screen the $mail i see the right mail.

in the catalina i see:

7/20/2010 4:33:14 PM: Mail: 4672: CRRBF0631I: User 'builder' does not have a val
id email address defined to receive mail notifications.

But the email is ok and it worked with the same email before.

Can you help?

Thanks,

permanent link
Brent Ulbricht (2.5k11) | answered Jul 20 '10, 1:46 p.m.
JAZZ DEVELOPER
Hi Shiran,

Could you give this script a try? If this doesn't work, if you could retrieve the server side exception like we did on one of the previous scripts that would help in figuring out what is happening. Also, if there is anything special about the user such as if it is a LDAP user.

use strict;


use BuildForge::Services;

my $conn = new BuildForge::Services::Connection('localhost');
my $token = $conn->authUser('root', 'root');

my $userLogin = 'User1';
my $user = BuildForge::Services::DBO::User->findByLogin($conn, $userLogin);
die("Could not find user login: " . $userLogin) unless defined($user);

my $oldUserEmail = $user->getEmail();
my $newUserEmail = 'User1@my.company.com';

$user->setEmail($newUserEmail);
$user = $user->update();

$user = BuildForge::Services::DBO::User->findByLogin($conn, $userLogin);
die("Could not find user login: " . $userLogin) unless defined($user);

$newUserEmail = $user->getEmail();

print "Changed User Login " . $userLogin . " email from " . $oldUserEmail . " to " . $newUserEmail . ".\n";


bju

permanent link
Johnson Joseph (811) | answered Aug 18 '10, 10:04 a.m.
Bju,
This script works for me really good. Thanks for the script Can you please help me on below questions

1.Using API scripts is that possible to see the all step information
2.Is that possible to send the pass email to team at end of project pass message using API (any email id not the user email id)

Please let me know if you have any other questions. Thanks for your kind help


Thanks
Johnson


Hi bju,

Thanks for your help.
I did what you worth and i see in the command line that the variable changed, there was no error.

But when i start the build i see in the build forge that the variable was not change and due to that the build failed.

I need to change the environment of the build? there is such option?

Thanks,
Shiran


Hi,

This is an example of changing a build environment entry value. This will only change the environment variable value at the time of starting the build.


use strict;

use BuildForge::Services;

my $conn = new BuildForge::Services::Connection('localhost');
my $token = $conn->authUser('root', 'root');

my $projectName = 'MyProject';
my $project = BuildForge::Services::DBO::Project->findByName($conn, $projectName);
die("Could not find project named: " . $projectName) unless defined($project);

my $newBuild = BuildForge::Services::DBO::Build->create($conn, $project->getUuid());
die("Could not create build for project: " . $project->getName()) unless defined($newBuild);

my $buildEnvUuid = $newBuild->getBuildEnvUuid();
die("Did not get build env uuid") unless defined($buildEnvUuid);

my $buildEnv = BuildForge::Services::DBO::BuildEnvironment->findByUuid($conn, $buildEnvUuid);
die("Could not find build environment uuid: " . $buildEnvUuid) unless defined($buildEnv);

my $myEnvVar = 'MyVar';
my $buildEnvEntry = $buildEnv->getEntry($myEnvVar);
die("Could not get build env entry named: " . $myEnvVar) unless defined($buildEnvEntry);

my $oldBuildEnvEntryVal = $buildEnvEntry->getValue();
my $newBuildEnvEntryVal = 'NEW_VALUE';
$newBuild->updateBuildEnvEntryValue($buildEnvEntry->getUuid(), $newBuildEnvEntryVal);
print "Changed build env entry val from " . $oldBuildEnvEntryVal . " to " . $newBuildEnvEntryVal . "\n";

$newBuild = $newBuild->fireBuild();


bju

Hi bju,

It worked for 1 project but now when i try from a different stream or different project i get this message:

BuildForge::Ex::APIException: A valid Value must be specified.

I see that i get the information, for example:
buildEnv:
buildVar:

Do you know what is the problem?
Thanks for your help,
Shiran

permanent link
Johnson Joseph (811) | answered Aug 18 '10, 10:07 a.m.
Bju,
This script works for me really good. Thanks for the script Can you please help me on below questions

1.Using API scripts is that possible to see the all step information
2.Is that possible to send the pass email to team at end of project pass message using API (any email id not the user email id)

Please let me know if you have any other questions. Thanks for your kind help


Thanks
Johnson

Bju,
This script works for me really good. Thanks for the script Can you please help me on below questions

1.Using API scripts is that possible to see the all step information
2.Is that possible to send the pass email to team at end of project pass message using API (any email id not the user email id)

Please let me know if you have any other questions. Thanks for your kind help


Thanks
Johnson


Hi bju,

Thanks for your help.
I did what you worth and i see in the command line that the variable changed, there was no error.

But when i start the build i see in the build forge that the variable was not change and due to that the build failed.

I need to change the environment of the build? there is such option?

Thanks,
Shiran


Hi,

This is an example of changing a build environment entry value. This will only change the environment variable value at the time of starting the build.


use strict;

use BuildForge::Services;

my $conn = new BuildForge::Services::Connection('localhost');
my $token = $conn->authUser('root', 'root');

my $projectName = 'MyProject';
my $project = BuildForge::Services::DBO::Project->findByName($conn, $projectName);
die("Could not find project named: " . $projectName) unless defined($project);

my $newBuild = BuildForge::Services::DBO::Build->create($conn, $project->getUuid());
die("Could not create build for project: " . $project->getName()) unless defined($newBuild);

my $buildEnvUuid = $newBuild->getBuildEnvUuid();
die("Did not get build env uuid") unless defined($buildEnvUuid);

my $buildEnv = BuildForge::Services::DBO::BuildEnvironment->findByUuid($conn, $buildEnvUuid);
die("Could not find build environment uuid: " . $buildEnvUuid) unless defined($buildEnv);

my $myEnvVar = 'MyVar';
my $buildEnvEntry = $buildEnv->getEntry($myEnvVar);
die("Could not get build env entry named: " . $myEnvVar) unless defined($buildEnvEntry);

my $oldBuildEnvEntryVal = $buildEnvEntry->getValue();
my $newBuildEnvEntryVal = 'NEW_VALUE';
$newBuild->updateBuildEnvEntryValue($buildEnvEntry->getUuid(), $newBuildEnvEntryVal);
print "Changed build env entry val from " . $oldBuildEnvEntryVal . " to " . $newBuildEnvEntryVal . "\n";

$newBuild = $newBuild->fireBuild();


bju

Hi bju,

It worked for 1 project but now when i try from a different stream or different project i get this message:

BuildForge::Ex::APIException: A valid Value must be specified.

I see that i get the information, for example:
buildEnv:
buildVar:

Do you know what is the problem?
Thanks for your help,
Shiran

permanent link
Brent Ulbricht (2.5k11) | answered Aug 18 '10, 10:48 a.m.
JAZZ DEVELOPER
Bju,
This script works for me really good. Thanks for the script Can you please help me on below questions

1.Using API scripts is that possible to see the all step information
2.Is that possible to send the pass email to team at end of project pass message using API (any email id not the user email id)

Please let me know if you have any other questions. Thanks for your kind help


Thanks
Johnson


Hi,

Yes, you can use the Perl BuildForge::Services::DBO::Step.pm or Java com.buildforge.services.client.dbo.Step.java to get the step data.

For sending email, I was wondering if you have tried the .email dot command. You could have a step with the command text of something like '.email project_team@my.company.com'.

bju

permanent link
Johnson Joseph (811) | answered Aug 18 '10, 11:15 a.m.
Bju,
I added this line use BuildForge::Services::DBO::Step.pm; to my below perl script but I am getting this error syntax error at ./build.pl line 5, near "use BuildForge::Services::DBO::Step.

I am not sure is that right or not, In that case can you tell me how to use that command.

also can we add the .email option at end of the script ? or need to add that into step command ? Will be great If I can use that .email option from API script.



#!/usr/bin/perl
use strict;

use BuildForge::Services;
use BuildForge::Services::DBO::Step.pm;

my $conn = new BuildForge::Services::Connection('localhost');
my $token = $conn->authUser('root', 'root');

my $projectName = 'EMBEDAPAT_TEST';
my $project = BuildForge::Services::DBO::Project->findByName($conn, $projectName);
die("Could not find project named: " . $projectName) unless defined($project);

my $newBuild = BuildForge::Services::DBO::Build->create($conn, $project->getUuid());
die("Could not create build for project: " . $project->getName()) unless defined($newBuild);

my $buildEnvUuid = $newBuild->getBuildEnvUuid();
die("Did not get build env uuid") unless defined($buildEnvUuid);

my $buildEnv = BuildForge::Services::DBO::BuildEnvironment->findByUuid($conn, $buildEnvUuid);
die("Could not find build environment uuid: " . $buildEnvUuid) unless defined($buildEnv);

my $myEnvVar = 'BUILDFILE';
my $buildEnvEntry = $buildEnv->getEntry($myEnvVar);
die("Could not get build env entry named: " . $myEnvVar) unless defined($buildEnvEntry);

my $oldBuildEnvEntryVal = $buildEnvEntry->getValue();
my $newBuildEnvEntryVal = 'Install/KING/EMBEDA_PAT/100811/100818_build_nosql.xml';
$newBuild->updateBuildEnvEntryValue($buildEnvEntry->getUuid(), $newBuildEnvEntryVal);
print "Changed build env entry val from " . $oldBuildEnvEntryVal . " to " . $newBuildEnvEntryVal . "\n";

$newBuild = $newBuild->fireBuild();

Once again thanks for your great help

Thanks
Johsnon

Bju,
This script works for me really good. Thanks for the script Can you please help me on below questions

1.Using API scripts is that possible to see the all step information
2.Is that possible to send the pass email to team at end of project pass message using API (any email id not the user email id)

Please let me know if you have any other questions. Thanks for your kind help


Thanks
Johnson


Hi,

Yes, you can use the Perl BuildForge::Services::DBO::Step.pm or Java com.buildforge.services.client.dbo.Step.java to get the step data.

For sending email, I was wondering if you have tried the .email dot command. You could have a step with the command text of something like '.email project_team@my.company.com'.

bju

permanent link
Brent Ulbricht (2.5k11) | answered Aug 18 '10, 1:50 p.m.
JAZZ DEVELOPER
Bju,
I added this line use BuildForge::Services::DBO::Step.pm; to my below perl script but I am getting this error syntax error at ./build.pl line 5, near "use BuildForge::Services::DBO::Step.

I am not sure is that right or not, In that case can you tell me how to use that command.

also can we add the .email option at end of the script ? or need to add that into step command ? Will be great If I can use that .email option from API script.


Hi,

Before recommending a solution, it probably would be good to step back a bit so that I understand what information you would like to get about the step. Is there a particular piece of data that you're trying to retrieve?

As for the email, the .email dot command would have to be in the step command text. I can show you some code for adding a step to the project or altering an existing step to add another command.

However, if you're not interested in altering your project steps, you might do an Internet search on the words: Send Email Perl MIME-Lite . You should get some links for examples sending email. The MIME-Lite package is one of a number of Perl packages that can be used in Perl code to send email.

bju

permanent link
Johnson Joseph (811) | answered Aug 18 '10, 3:15 p.m.
Bju,
We have plan to give the perl script to developers to run the build at any time(Execute the build from command line). We don't want to give the console access.

Each project has 14 steps at the end of 14 step need to send the project pass notification to developer

Using that perl script is that possible to see the step messages like running,passed,failed dont want to see the step log or if you have any idea to see the step log that will be great too. (basically need to know which step currently running )

I added the .email jjoseph@outcome.com at the end of step command text but I coudnt get the eamil here is the step log Step sending generic step email to: jjoseph@outcome.com

But I didnt get this email .

Let me know if you need more info

Thanks
Johnson



Bju,
I added this line use BuildForge::Services::DBO::Step.pm; to my below perl script but I am getting this error syntax error at ./build.pl line 5, near "use BuildForge::Services::DBO::Step.

I am not sure is that right or not, In that case can you tell me how to use that command.

also can we add the .email option at end of the script ? or need to add that into step command ? Will be great If I can use that .email option from API script.


Hi,

Before recommending a solution, it probably would be good to step back a bit so that I understand what information you would like to get about the step. Is there a particular piece of data that you're trying to retrieve?

As for the email, the .email dot command would have to be in the step command text. I can show you some code for adding a step to the project or altering an existing step to add another command.

However, if you're not interested in altering your project steps, you might do an Internet search on the words: Send Email Perl MIME-Lite . You should get some links for examples sending email. The MIME-Lite package is one of a number of Perl packages that can be used in Perl code to send email.

bju

permanent link
Brent Ulbricht (2.5k11) | answered Aug 18 '10, 11:35 p.m.
JAZZ DEVELOPER
Hi,

I've pasted some sample code of displaying the running status. You could do some fancier stuff with the display to the console, but I've just printed the output approximately every second. I used the script that you had pasted. The last part after firing the build contains the new code.

I tried the .email on my system here and did get the email. In your test did it ever arrive?


#!/usr/bin/perl
use strict;

use BuildForge::Services;

my $conn = new BuildForge::Services::Connection('localhost');
my $token = $conn->authUser('root', 'root');

my $projectName = 'EMBEDAPAT_TEST';
my $project = BuildForge::Services::DBO::Project->findByName($conn, $projectName);
die("Could not find project named: " . $projectName) unless defined($project);

my $newBuild = BuildForge::Services::DBO::Build->create($conn, $project->getUuid());
die("Could not create build for project: " . $project->getName()) unless defined($newBuild);

my $buildEnvUuid = $newBuild->getBuildEnvUuid();
die("Did not get build env uuid") unless defined($buildEnvUuid);

my $buildEnv = BuildForge::Services::DBO::BuildEnvironment->findByUuid($conn, $buildEnvUuid);
die("Could not find build environment uuid: " . $buildEnvUuid) unless defined($buildEnv);

my $myEnvVar = 'BUILDFILE';
my $buildEnvEntry = $buildEnv->getEntry($myEnvVar);
die("Could not get build env entry named: " . $myEnvVar) unless defined($buildEnvEntry);

my $oldBuildEnvEntryVal = $buildEnvEntry->getValue();
my $newBuildEnvEntryVal = 'Install/KING/EMBEDA_PAT/100811/100818_build_nosql.xml';
$newBuild->updateBuildEnvEntryValue($buildEnvEntry->getUuid(), $newBuildEnvEntryVal);
print "Changed build env entry val from " . $oldBuildEnvEntryVal . " to " . $newBuildEnvEntryVal . "\n";

$newBuild = $newBuild->fireBuild();

my $timeOut = 300;

my $buildState = $newBuild->getState();

for (my $i = 0; ($i < $timeOut) && ($buildState ne 'COMPLETED'); $i++) {
sleep 1;
$newBuild = BuildForge::Services::DBO::Build->findByUuid($conn, $newBuild->getUuid());
die("Could not get the build") unless defined($newBuild);
$buildState = $newBuild->getState();
my $results = $newBuild->getResults();
die("Could not get the results for the build") unless defined($results);
print $i . ": Project Name: " . $projectName . "\tTag: " . $newBuild->getTag() . "\tState: " . $newBuild->getState() . "\n";
foreach my $result (@$results) {
print "\tStep Description: " . $result->getDescription() . "\tStep Result: " . $result->getResult() . "\n";
}
print "\n";
}

die("Build did not complete in under " . $timeOut . " seconds.") if ($buildState ne 'COMPLETED');

print "Final Build Result: " . $newBuild->getResult() . "\n";



bju

permanent link
Johnson Joseph (811) | answered Aug 19 '10, 10:00 a.m.
BJU,
Your the man, I can able to see all the step messages . Thanks for the great help.

.email doesn't work for me I dont know why, Here is the log from build forge serevr
I used this syntax on step command text .email jjoseph@outcome.com

Wed 18 Aug 2010 11:09:28 AM EDT: Mail: 5572: CRRBF1482I: Selected external user:
Wed 18 Aug 2010 11:09:28 AM EDT: Mail: 5572: CRRBF0780I: Generating email to using [] template via .
Wed 18 Aug 2010 11:09:28 AM EDT: Mail: 5572: CRRBF0998E: Attempt to send mail to using failed : no data in this part

Once again thanks for the great help

Thanks
Johsnon

Hi,

I've pasted some sample code of displaying the running status. You could do some fancier stuff with the display to the console, but I've just printed the output approximately every second. I used the script that you had pasted. The last part after firing the build contains the new code.

I tried the .email on my system here and did get the email. In your test did it ever arrive?


#!/usr/bin/perl
use strict;

use BuildForge::Services;

my $conn = new BuildForge::Services::Connection('localhost');
my $token = $conn->authUser('root', 'root');

my $projectName = 'EMBEDAPAT_TEST';
my $project = BuildForge::Services::DBO::Project->findByName($conn, $projectName);
die("Could not find project named: " . $projectName) unless defined($project);

my $newBuild = BuildForge::Services::DBO::Build->create($conn, $project->getUuid());
die("Could not create build for project: " . $project->getName()) unless defined($newBuild);

my $buildEnvUuid = $newBuild->getBuildEnvUuid();
die("Did not get build env uuid") unless defined($buildEnvUuid);

my $buildEnv = BuildForge::Services::DBO::BuildEnvironment->findByUuid($conn, $buildEnvUuid);
die("Could not find build environment uuid: " . $buildEnvUuid) unless defined($buildEnv);

my $myEnvVar = 'BUILDFILE';
my $buildEnvEntry = $buildEnv->getEntry($myEnvVar);
die("Could not get build env entry named: " . $myEnvVar) unless defined($buildEnvEntry);

my $oldBuildEnvEntryVal = $buildEnvEntry->getValue();
my $newBuildEnvEntryVal = 'Install/KING/EMBEDA_PAT/100811/100818_build_nosql.xml';
$newBuild->updateBuildEnvEntryValue($buildEnvEntry->getUuid(), $newBuildEnvEntryVal);
print "Changed build env entry val from " . $oldBuildEnvEntryVal . " to " . $newBuildEnvEntryVal . "\n";

$newBuild = $newBuild->fireBuild();

my $timeOut = 300;

my $buildState = $newBuild->getState();

for (my $i = 0; ($i <timeOut>findByUuid($conn, $newBuild->getUuid());
die("Could not get the build") unless defined($newBuild);
$buildState = $newBuild->getState();
my $results = $newBuild->getResults();
die("Could not get the results for the build") unless defined($results);
print $i . ": Project Name: " . $projectName . "\tTag: " . $newBuild->getTag() . "\tState: " . $newBuild->getState() . "\n";
foreach my $result (@$results) {
print "\tStep Description: " . $result->getDescription() . "\tStep Result: " . $result->getResult() . "\n";
}
print "\n";
}

die("Build did not complete in under " . $timeOut . " seconds.") if ($buildState ne 'COMPLETED');

print "Final Build Result: " . $newBuild->getResult() . "\n";



bju

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.