How to Redeploy only if the bpmn file has a newer version tag

How to Redeploy only if the bpmn file has a newer version tag?

The deploymentbuilder does not give any method like deployIfUpdated.
So I thought I should compare ProcessDefinition.getVersion() to the value of versionTag obtained somehow from BpmnModelInstance. But these two fields dont seem to carry matching number.

My current code snippet is as follows, here i am only checking if the process key is not found in the deployed diagrams then deploy the bpmn. But I need to make edits to bpmn file via modeller and bump up the versionTag and save the file and then when it reaches this code I want it to redeploy the diagram. If I dont increase the versionTag, my bpmn file should not be redeployed. (Hoping the redeployment only costs some performance and not huge disc spaces)

boolean foundDeployed = false;

definitions = rps.createProcessDefinitionQuery().list();
for (ProcessDefinition pd : definitions) {
log.info("any already deployed " + " Version " + pd.getVersion() + " id " + pd.getId());
if (pd.getKey().equalsIgnoreCase(Param_BpmnKey)) {
foundDeployed = true;
}
}
log.info("foundDeployed " + foundDeployed);

if (! foundDeployed) {
DeploymentBuilder deploymentBuilder = rps.createDeployment().name(“CamDeplName”);
deploymentBuilder.addInputStream(f.getName() , fis);
Deployment dep = deploymentBuilder.deploy();
}

The processDefinition.getVersion() method returns an integer. That is the engine’s version of the deployed process definition and gets incremented automatically every time you redeploy the process.

The processDefinition.getVersionTag() method returns a string. That is the versionTag attribute that was specified in the process model.

If you want to check for a higher version tag in your model and condition deployment on that, you should base your comparison on the getVersionTag().

For BpmnModelInstance side of things, this is how we fetch the version tag, as it doesn’t seem to be exposed by the API otherwise:

String versionTag = bpmnModelInstance.getDocument()
				.getElementsByNameNs("http://www.omg.org/spec/BPMN/20100524/MODEL", "process")
				.get(0).getAttribute("http://camunda.org/schema/1.0/bpmn", "versionTag");

Beware of checking for a new version like that: if (0.10 > 0.9) :slight_smile:

1 Like

you can fetch it trough the process definition:
processDefinition.getVersionTag()

Sorry, I was referring to the model API, not the repository API.

Because we want to verify the version of the new model before it goes into the repository. At least this is how understood the question.

1 Like

Thanks for the reply. Let me try this way of parsing the bpmn file and get back if i have any more query,