execute Build forge project from command line
20 answers
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
Hi Shiran,
You can use the Build Forge Perl services layer client to execute a Build Forge project. To get the Perl services layer client, you can download it from a browser by going to http://<Host>:<Port>/clients .
I've included some sample code below that should give you an idea of the statements that will be needed. Of course, you will need to alter the code for things like services layer host, port, user name, password, and project name.
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);
if (defined($project)) {
my $newBuild = BuildForge::Services::DBO::Build->fire($conn, $project->getUuid());
} else {
print "Cound not find project named: " . $projectName . "\n";
}
bju
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
Hi Shiran,
You can use the Build Forge Perl services layer client to execute a Build Forge project. To get the Perl services layer client, you can download it from a browser by going to http://<Host>:<Port>/clients .
I've included some sample code below that should give you an idea of the statements that will be needed. Of course, you will need to alter the code for things like services layer host, port, user name, password, and project name.
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);
if (defined($project)) {
my $newBuild = BuildForge::Services::DBO::Build->fire($conn, $project->getUuid());
} else {
print "Cound not find project named: " . $projectName . "\n";
}
bju
Thanks, this is very helpful.
Now i am trying to change an exiting environment variable from the script.
I want to start a build of specific project but first i want to set a few values of the project environment.
I found a few examples to create a new environment.
Can you send an example to how i can change existing environment?
Thanks,
Shiran
Thanks, this is very helpful.
Now i am trying to change an exiting environment variable from the script.
I want to start a build of specific project but first i want to set a few values of the project environment.
I found a few examples to create a new environment.
Can you send an example to how i can change existing environment?
Thanks,
Shiran
Hi Shiran,
Here is some code that displays how to set an environment variable value.
use strict;
use BuildForge::Services;
my $conn = new BuildForge::Services::Connection('localhost');
my $token = $conn->authUser('root', 'root');
my $envName = 'MyEnv';
my $env = BuildForge::Services::DBO::Environment->findByName($conn, $envName);
if (defined($env)) {
my $envEntryName = 'MyVariable';
my $envEntry = $env->getEntry($envEntryName);
if (defined($envEntry)) {
my $oldEnvEntryValue = $envEntry->getValue();
my $newEnvEntryValue = 'NewValue';
$envEntry->setValue($newEnvEntryValue);
$envEntry = $envEntry->update();
print "Changed variable " . $envEntryName . " from " . $oldEnvEntryValue . " to " . $envEntry->getValue() . "\n";
} else {
print "Cound not find environment entry named: " . $envEntryName . "\n";
}
} else {
print "Cound not find environment named: " . $envName . "\n";
}
bju
Thanks, this is very helpful.
Now i am trying to change an exiting environment variable from the script.
I want to start a build of specific project but first i want to set a few values of the project environment.
I found a few examples to create a new environment.
Can you send an example to how i can change existing environment?
Thanks,
Shiran
Hi Shiran,
Here is some code that displays how to set an environment variable value.
use strict;
use BuildForge::Services;
my $conn = new BuildForge::Services::Connection('localhost');
my $token = $conn->authUser('root', 'root');
my $envName = 'MyEnv';
my $env = BuildForge::Services::DBO::Environment->findByName($conn, $envName);
if (defined($env)) {
my $envEntryName = 'MyVariable';
my $envEntry = $env->getEntry($envEntryName);
if (defined($envEntry)) {
my $oldEnvEntryValue = $envEntry->getValue();
my $newEnvEntryValue = 'NewValue';
$envEntry->setValue($newEnvEntryValue);
$envEntry = $envEntry->update();
print "Changed variable " . $envEntryName . " from " . $oldEnvEntryValue . " to " . $envEntry->getValue() . "\n";
} else {
print "Cound not find environment entry named: " . $envEntryName . "\n";
}
} else {
print "Cound not find environment named: " . $envName . "\n";
}
bju
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 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,
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:
Do you know what is the problem?
Thanks for your help,
Shiran
Hi,
It's hard to tell from that information. The message seems to indicate that there may be a problem with the build env value being updated. Without seeing your script code or knowing the variable and its type that you're trying to set though, I'm not sure.
If you have access to the Management Console computer and its files, you could look in the <BF_INSTALL_DIR>/server/tomcat/logs/catalina<date>.log to see if the server has more information (stack trace and exception message) indicating why it failed.
bju
It's hard to tell from that information. The message seems to indicate that there may be a problem with the build env value being updated. Without seeing your script code or knowing the variable and its type that you're trying to set though, I'm not sure.
If you have access to the Management Console computer and its files, you could look in the <BF_INSTALL_DIR>/server/tomcat/logs/catalina<date>.log to see if the server has more information (stack trace and exception message) indicating why it failed.
bju
Hi,
It's hard to tell from that information. The message seems to indicate that there may be a problem with the build env value being updated. Without seeing your script code or knowing the variable and its type that you're trying to set though, I'm not sure.
If you have access to the Management Console computer and its files, you could look in the <BF_INSTALL_DIR>/server/tomcat/logs/catalina<date>.log to see if the server has more information (stack trace and exception message) indicating why it failed.
bju
This is from the log:
Jul 11, 2010 5:09:24 PM com.buildforge.services.server.text.TextFormatter render
WARNING: Missing translation: locale= key=
Jul 11, 2010 5:09:24 PM com.buildforge.services.server.api.APIServerConnection process
WARNING: !!!
com.buildforge.services.common.api.APIException: A valid Value must be specified.
at com.buildforge.services.common.api.APIException.invalid(APIException.java:223)
at com.buildforge.services.server.manager.BuildEnvironmentEntryManager.updateValue(BuildEnvironmentEntryManager.java:358)
at com.buildforge.services.server.api.commands.BuildCommands.updateBuildEnvEntry(BuildCommands.java:512)
at com.buildforge.services.server.api.commands.BuildCommands.invoke(BuildCommands.java:139)
at com.buildforge.services.server.api.APICommandProcessor.process(APICommandProcessor.java:261)
at com.buildforge.services.server.api.APIServerConnection.handleRequest(APIServerConnection.java:206)
at com.buildforge.services.server.api.APIServerConnection.process(APIServerConnection.java:153)
at com.buildforge.services.server.dispatch.handler.BufferedConnection.run(BufferedConnection.java:243)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
at java.lang.Thread.run(Thread.java:810)
Jul 11, 2010 5:09:24 PM com.buildforge.services.server.text.TextFormatter render
WARNING: Missing translation: locale= key=
Jul 11, 2010 5:09:24 PM com.buildforge.services.server.text.TextFormatter render
WARNING: Missing translation: locale= key=
Can you help?
Thanks,
Hi,
From the stack trace in your last post, it seems that the build environment entry that you're trying to update is a pulldown. If this is the case, the new pulldown value that you're trying to set must be one of the possible values for that pulldown.
bju
Thanks! i didn't notice that i don't have it in the pulldown.
page 1of 1 pagesof 2 pages