Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Waiting state

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

0 votes



6 answers

Permanent link
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

0 votes


Permanent link
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

0 votes


Permanent link
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

0 votes


Permanent link
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

0 votes


Permanent link
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

0 votes


Permanent link
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

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Oct 13 '10, 3:07 a.m.

Question was seen: 6,876 times

Last updated: Oct 13 '10, 3:07 a.m.

Confirmation Cancel Confirm