Fire a build with extended environment
The use cae is that
I have a project
When fire the project I need to extend curent environment entrys with more entrys and also modify existing.
The solution I tryed was to create a new envirnment including all entrys and overiding that in a Build.request
But the overide do not work so br.setEnvironmentUuid(newEnv.getUuid()); failes to replace the original envirnment, so it is using the default.
Any one have a better solution for my use case
The code is this
@POST
@Path("/fire")
@Produces(MediaType.APPLICATION_JSON)
@Consumes("application/x-www-form-urlencoded")
public ExtjsResponse getFireBuild(
@Context HttpServletRequest request,
//@Context UriInfo ui,
MultivaluedMap<String,String> formData,
@FormParam("dummy") String dummy
) {
ExtjsResponse res = new ExtjsResponse();
//Map<String, String[]> params = request.getParameterMap();
//MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
String planUuid = formData.getFirst("uuid");//this.getListValue(queryParams, "uuid",true);
String ENVIRONMENT = formData.getFirst("ENVIRONMENT");//this.getListValue(queryParams, "ENVIRONMENT",false);
String CELL_NAME = formData.getFirst("CELL_NAME");//this.getListValue(queryParams, "CELL_NAME",false);
// Validate the cell and that user has access rights to it
raf = ApiConnection.getInstance(request,true);
Environment newEnv = null;
try {
Environment env = Environment.findByName(raf.conn, "RAFW_" + ENVIRONMENT + "_" + CELL_NAME);
if (env == null) {
res.success = false;
res.message = "CELL " + formData.toString() + " not found " + CELL_NAME;
// Redirect user to login page
return res;
}
EnvironmentEntry tEntry = env.getEntry("CELL_NAME");
if (tEntry == null) {
res.success = false;
res.message = "CELL_NAME not found in RAFW_" + CELL_NAME;
// Redirect user to login page
return res;
}
tEntry = env.getEntry("ENVIRONMENT");
if (tEntry == null) {
res.success = false;
res.message = "ENVIRONMENT not found in RAFW_" + CELL_NAME;
// Redirect user to login page
return res;
}
} catch (IOException e) {
e.printStackTrace();
res.success = false;
res.message = "IOexception when finding RAFW_" + CELL_NAME;
// Redirect user to login page
return res;
} catch (ServiceException e) {
e.printStackTrace();
res.success = false;
res.message = "ServiceException when finding RAFW_" + CELL_NAME;
// Redirect user to login page
return res;
}
try {
//Build.Request buildRequest = new Build.Request(raf.conn, planUuid);
//Build buildJob = Build.create(raf.conn, planUuid);
//String buildEnvUuid = buildJob.getBuildEnvironmentUuid();
// job created lets add environment entrys
//BuildEnvironment env = BuildEnvironment.findByUuid(raf.conn, buildEnvUuid);
//Environment env = Environment.findByUuid(raf.conn, buildEnvUuid);
//if( env == null){
// res.success = false;
// res.message = "No environment defined for project ";
// Redirect user to login page
// return res;
//}
logger.log(Level.WARNING, "find project by uuid" );
Project proj = Project.findByUuid(raf.conn, planUuid);
if (proj == null) {
res.success = false;
res.message = "Project with uuid " + planUuid + " Not found";
return res;
}
//Environment oldEnv = Environment.findByUuid(raf.conn, proj.getEnvironmentUuid());
//Environment newEnv = oldEnv.clone();
newEnv = new Environment(raf.conn);
newEnv.setLevel(proj.getLevel());
logger.log(Level.WARNING, "have set project level on new env to " + proj.getLevel());
newEnv.setName("11111");
logger.log(Level.WARNING, "have set name on new env to " + "1111");
//logger.log(Level.WARNING, "Cloned existing environment" );
//for (Integer i = 0; i < newEnv.getEntryCount();i++) {
// newEnv.removeEntry(i);
//}
//logger.log(Level.WARNING, "Removed all old entrys" );
//newEnv.update();
//logger.log(Level.WARNING, "Updated new environment" );
//Environment newEnv = new Environment(raf.conn);
// Add all environment entrys from quearyParams
for (Entry<String, List<String>> entry : formData.entrySet()) {
entry.getKey();
EnvironmentEntry envEntry = new EnvironmentEntry(raf.conn,newEnv);
envEntry.setParameterName(entry.getKey());
List<String> values = entry.getValue();
if (values.size() > 0) {
envEntry.setParameterValue(values.get(0));
} else {
envEntry.setParameterValue("");
}
envEntry.setVariableType(EnvironmentEntryDBO.VariableType.STANDARD);
envEntry.setMode(EnvironmentEntryDBO.Mode.READ_ONLY);
envEntry.update();
newEnv.addEntry(envEntry);
}
logger.log(Level.WARNING, "Added entrys from form" );
//newEnv.update();
//logger.log(Level.WARNING, "Updated new environment" );
//newEnv.setName(newEnv.getName() + 1);
//newEnv.setName("12121212");
//logger.log(Level.WARNING, "Seting name of newEnv" );
newEnv.create();
//newEnv.update();
logger.log(Level.WARNING, "New env created" );
Build.Request br = new Build.Request(proj);
logger.log(Level.WARNING, "created a build request" );
logger.log(Level.WARNING," Org env " + br.getEnvironmentUuid());
br.setEnvironmentUuid(newEnv.getUuid());
logger.log(Level.WARNING, "attached the new environment " + newEnv.getUuid() );
logger.log(Level.WARNING," New env " + br.getEnvironmentUuid());
//Build buildJob = Build.create(br);
//logger.log(Level.WARNING, "created a job " + buildJob.getUuid());
//buildJob.unlock();
//logger.log(Level.WARNING, "Unlocked the build ");
// fire job
//Build.fire(raf.conn, buildJob.getUuid());
Build.fire(br);
logger.log(Level.WARNING, "job fired" );
newEnv.delete();
logger.log(Level.WARNING, "Temporary environment deleted" );
res.success = true;
//res.message = buildJob.getUuid();
res.message = "Jobb scheduled";
// Redirect user to login page
return res;
} catch (IOException e) {
e.printStackTrace();
res.success = false;
res.message = "IOexception when creating job";
// Redirect user to login page
return res;
} catch (ServiceException e) {
e.printStackTrace();
res.success = false;
res.message = "ServiceException when creating job";
// Redirect user to login page
return res;
} finally {
if (newEnv != null){
try {
newEnv.delete();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
res.success = false;
res.message = "IOException when deleting new Env";
// Redirect user to login page
return res;
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
res.success = false;
res.message = "ServiceException when deleting new Env";
// Redirect user to login page
return res;
}
}
}
}
|
3 answers
This appears to be a question about the Build Forge client API, not RTC Build API, but we faced a similar issue when implementing the RTC / Build Forge integration. The problem was how to send the RTC build's properties to the corresponding Build Forge build when starting it. Our solution was to:
(a) modify the original project's environment to add any RTC build properties that were unknown to the environment
(b) update the Build Forge build's environment (a copy of the project environment) with any new values from the corresponding property in the RTC build, before firing the BF build.
|
Hi Max,
It sounds like you just want to request a build and override or define some build properties. If that's the case, it can already be done in both the Eclipse client and Web UI. Just change the property value or add a new property altogether. Scott |
Hi
Thanks for the input
But I am extending RAF with a new gui
And like To do it in Java
Max
|
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.