Cybersecurity
DevOps Cloud (ADM)
IT Operations Cloud
Currently the best way for managing Build Information is through the Build Info file however, this is a static file which needs to be updated manually before each run.
To work around this it is possible to create a Java Application which perform the updates.
Borland Technical Support have created one that this is run through command line so it can be run as a ‘Process Executor’ test script. (If required you could also build a front-end to this).
The code itself is provided below, so that it can be modify as required:
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class XMLWriter {
private static String product;
private static String strversion;
private static String strbuild;
public static void main(String args[]) {
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("ProjectBuildInfo");
doc.appendChild(rootElement);
Element list = doc.createElement("BuildEntryList");
rootElement.appendChild(list);
Element buildEntry = doc.createElement("BuildEntry");
list.appendChild(buildEntry);
Attr attr = doc.createAttribute("name");
product = args[0];
attr.setValue(product);
buildEntry.setAttributeNode(attr);
Element version = doc.createElement("Version");
strversion = args[1];
version.appendChild(doc.createTextNode(strversion));
buildEntry.appendChild(version);
Element build = doc.createElement("BuildNr");
strbuild = args[2];
build.appendChild(doc.createTextNode(strbuild));
buildEntry.appendChild(build);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File("C:\\ProgramData\\SilkCentral\\BuildInfos\\BuildInfo.xml"));
transformer.transform(source, result);
System.out.println("File saved!");
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (TransformerException tfe) {
tfe.printStackTrace();
}
}
}
This code will create a file called BuildInfo.xml in the location C:\ProgramData\SilkCentral\BuildInfos.
If you would like a copy of the JAR file please log a Support Incident.
To use the JAR file:
1. Open up a command window, and run the following command:
java –cp <location of jar file> buildinfo.XMLWriter “Demo Product” 12 2
As this has no manifest it will be necessary to run the ClassName, which will take the three arguments passed to the execution and set them as the BuildInfo.xml values;
2. Modify the Project Settings so that the file the Project is looking for is BuildInfo.xml.
3. Create a test in Silk Central, which will allow this test to be run before the executions. On a Test Container right-click and create a new Test using the Type ‘ProcessExecutor Test’, which will allow you to configure the properties to run the jar file through command line:
4. Now that it is configured this test can be added to an execution plan so that when run first this script will create the new file, and any dependent execution plan will use the new parameters defined on the test.
If you have any questions or issues when configuring this, or would like a copy of the .JAR file then log a Support Incident and the JAR file and additional support can be provided.
*For Silk Central 18.0 and above, please use the following article due to the change of location for the BuildInfo.xml:
https://community.microfocus.com/borland/test/silk_central/w/knowledge_base/29516/creating-buildinfo-file-automatically---sc-18-0-and-above