It's all about the answers!

Ask a question

Waiting state


shiran shem tov (1211114) | asked Oct 13 '10, 3:07 a.m.
Hi,

I have a limitation on one of my project to run 1 job each time.
When another job is in waiting state i want to send mail to the person who started the job.

There is no waiting notify like pass\fail notify.

Does someone know what can i do?

Thanks,
shiran

6 answers



permanent link
Brent Ulbricht (2.5k11) | answered Oct 13 '10, 3:10 p.m.
JAZZ DEVELOPER
Hi,

I have a limitation on one of my project to run 1 job each time.
When another job is in waiting state i want to send mail to the person who started the job.

There is no waiting notify like pass\fail notify.

Does someone know what can i do?

Thanks,
shiran


Hi shiran,

The only thing I can think of is to use the Services Layer API.

bju

permanent link
shiran shem tov (1211114) | answered Oct 14 '10, 3:25 a.m.
Hi,

I have a limitation on one of my project to run 1 job each time.
When another job is in waiting state i want to send mail to the person who started the job.

There is no waiting notify like pass\fail notify.

Does someone know what can i do?

Thanks,
shiran


Hi shiran,

The only thing I can think of is to use the Services Layer API.

bju

Do you have an example? or document i can read, to see how i can do it.

Thanks

permanent link
Brent Ulbricht (2.5k11) | answered Oct 25 '10, 5:22 p.m.
JAZZ DEVELOPER
Hi,

I have a limitation on one of my project to run 1 job each time.
When another job is in waiting state i want to send mail to the person who started the job.

There is no waiting notify like pass\fail notify.

Does someone know what can i do?

Thanks,
shiran


Hi shiran,

The only thing I can think of is to use the Services Layer API.

bju

Do you have an example? or document i can read, to see how i can do it.

Thanks

Hi shiran,

This is an example of something you could use to fire a build, wait around for the build to get out of waiting state for 60 seconds, and if still in waiting to run some checks if it is due to another running build. If the build is waiting due to another running build, an email is sent using MIME::Lite.


use strict;

use MIME::Lite;

use BuildForge::Services;

my $host = 'localhost';
my $user = 'root';
my $password = 'root';
my $projectName = 'MyProject';

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

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

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

$build = $build->fireBuild();
die("Build not defined after fireBuild executed.") unless defined($build);

my $sleepTime = 60;
my $state = $build->getState();
for (my $i = 0; (($i < $sleepTime) && ($state eq 'WAITING')); $i++) {
sleep 1;
$build = BuildForge::Services::DBO::Build->findByUuid($conn, $build->getUuid());
die("Cound not find build") unless defined($build);
$state = $build->getState();
}

if (($state eq 'WAITING') && ($project->getRunLimit() == 1)) {
my $builds = BuildForge::Services::DBO::Build->findByProjectUuid($conn, $project->getUuid());
my $runningBldCount = 0;
foreach my $bld (@$builds) {
if ($bld->getState() eq 'RUNNING') {
$runningBldCount++;
}
}
if ($runningBldCount > 0) {
my $to = "admin\@my.company.com";
my $from = "buildforge\@my.company.com";
my $subject = "Build Forge: Build in WAITING State";
my $message = "There are " . $runningBldCount . " running builds.";
my $msg = MIME::Lite->new(From => $from, To => $to, Subject => $subject, Data => $message);
MIME::Lite->send('smtp', 'localhost', Timeout => 60);
$msg->send();
} else {
print "The build is in WAITING state, but not due to another build currently running.\n";
}
}

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


bju

permanent link
Jonas Gryder (11663) | answered Oct 26 '10, 2:26 p.m.
This could be very useful for our shop as well, but I am unsure of the implementation.

After modifying the script for our installation, I assume I save it as a .pl file. How do I invoke it from a BuildForge step? It would seem that it cannot be the same project as the one that I have set to a single user, since that one won't run the step until prior jobs have finished. Do I create a separate BF job that calls this script and includes the limited job as a parameter?





use strict;

use MIME::Lite;

use BuildForge::Services;

my $host = 'localhost';
my $user = 'root';
my $password = 'root';
my $projectName = 'MyProject';

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

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

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

$build = $build->fireBuild();
die("Build not defined after fireBuild executed.") unless defined($build);

my $sleepTime = 60;
my $state = $build->getState();
for (my $i = 0; (($i <sleepTime>findByUuid($conn, $build->getUuid());
die("Cound not find build") unless defined($build);
$state = $build->getState();
}

if (($state eq 'WAITING') && ($project->getRunLimit() == 1)) {
my $builds = BuildForge::Services::DBO::Build->findByProjectUuid($conn, $project->getUuid());
my $runningBldCount = 0;
foreach my $bld (@$builds) {
if ($bld->getState() eq 'RUNNING') {
$runningBldCount++;
}
}
if ($runningBldCount > 0) {
my $to = "admin\@my.company.com";
my $from = "buildforge\@my.company.com";
my $subject = "Build Forge: Build in WAITING State";
my $message = "There are " . $runningBldCount . " running builds.";
my $msg = MIME::Lite->new(From => $from, To => $to, Subject => $subject, Data => $message);
MIME::Lite->send('smtp', 'localhost', Timeout => 60);
$msg->send();
} else {
print "The build is in WAITING state, but not due to another build currently running.\n";
}
}

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


bju

permanent link
Brent Ulbricht (2.5k11) | answered Oct 26 '10, 5:08 p.m.
JAZZ DEVELOPER
Hi,

I'm not sure how far along you are, but the first step you'll need is to get the services layer client API code. You can do this by downloading it from your management console host (http://host:port/clients) . There is a link to download both the Java and Perl client code.

Once you've got the client and saved the script (yes, .pl is probably the best extension for it), you'll need to include the services layer client in the path when invoking (perl -I/tmp/bf/sl/client my_script.pl or add the path to the env variable PERL5LIB) .

The one thing about running the script from another Build Forge step is that you more than likely want to set up a separate user to handle the script because if you use the same user as someone logged into the UI - that UI user will get logged out.

The script can be improved as I was just trying to display an example. It would be better as you mention by adding command line parameters, etc.

bju

permanent link
Jonas Gryder (11663) | answered Nov 02 '10, 7:05 p.m.
Thanks!

Hi,

I'm not sure how far along you are, but the first step you'll need is to get the services layer client API code. You can do this by downloading it from your management console host (http://host:port/clients) . There is a link to download both the Java and Perl client code.

Once you've got the client and saved the script (yes, .pl is probably the best extension for it), you'll need to include the services layer client in the path when invoking (perl -I/tmp/bf/sl/client my_script.pl or add the path to the env variable PERL5LIB) .

The one thing about running the script from another Build Forge step is that you more than likely want to set up a separate user to handle the script because if you use the same user as someone logged into the UI - that UI user will get logged out.

The script can be improved as I was just trying to display an example. It would be better as you mention by adding command line parameters, etc.

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.