Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Dynamically Generate And Use Resource #4328

tomz ·

I'm using script code to create a resource and assign a node to it, but when I try to trigger a build using that resource, it gives an error.

The following is the code block:

def addTempResource(String resName, String hostName)
{
  def resman = ResourceManager.instance;
  def tempResourceCriteria = new HostNameNodeSelection();
  tempResourceCriteria.setOperator(Operator.matches_regular_expression);
  tempResourceCriteria.setValue(hostName);
  def tempResourceProvider = new ResourceProvider();
  tempResourceProvider.setNodeSelection(tempResourceCriteria);
  tempResourceProvider.setResourceCount("1");
  def resProviders = new ArrayList<ResourceProvider>();
  resProviders.add(tempResourceProvider);
  def finalResource = new Resource();
  finalResource.setName(resName);
  finalResource.setProviders(resProviders);
  resman.save(finalResource);
}

I can see the resource for the example I created when I use the web interface:
resource_exists.jpg

But I get the error on use:

Trigger Data Build for Presub Warming' is failed: Error allocating node for step 'master': Resource '************PresubWarmer' is not defined.

I've checked to ensure the actual resource name does case-sensitive match what the error message is saying. What am I missing?

  • replies 3
  • views 1206
  • stars 0
robinshen ADMIN ·

Use resman.save(finalResource, null) instead of resman.save(finalResource). The suggested method will take care of caching the resource so that build can find it.

robinshen ADMIN ·

Also make sure that this script runs on QB server.

tomz ·

It does run on the server, and this worked like a charm, thanks!