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.

system.getStorageDir() does not work as expected on agents #4091

drdt ·

In our environment, we have configured our global storage directory to be a network location '/netstorage/${node.getHostName()}'. The embedded hostname is because we have both staging and production servers, and when we backup/restore the database from one environment to the other, we need it to automatically not step on the workspace of the other server.

We then have scripts that reference this path via 'system.getStorageDir().getPath()'. However, when executed on a build agent, the local storage directory on the agent is returned.

linux server: /netstorage/rh7x64adm2-2
linux agent: /opt/qbagent-8811/storage
windows agent: F:\qbagent-8811\storage

I think this is a bug, since 'global storage directory' implies the storage directory is, well, global. If the global storage directory were node-specific, I would use 'grid.getServerNode().getStorageDir().getPath()' but that method doesn't exist.

What is the correct solution in this case?

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

This is by design, as global storage is only meaningful on server. When calling this method from agent, we previously throws exception. However sometimes it is convenient to make the call returning a local storage directory so that agent also has concept of storage (although local to agent installation, but it will be convenient for some use cases). Returning the same directory as on server will not work as most of the time the agent can not see the global directory on server.

drdt ·

Okay, I can understand this concern; you are right, there is no reason to access the global storage directory from the agent.

My use case is this: I am trying to derive the workspace root from the global storage directory path as follows:

  • sysStorageRoot = system.getStorageDir().getPath();
  • sysWorkspaceRoot = ${groovy:vars.getValue("sysStorageRoot").replaceAll("^/netstorage/","/workspaces/");}
    I can then reference vars.getValue("sysWorkspaceRoot") in the Advanced Settings on my 'root' configuration.

What I am having to do instead is define workspace root directly:

  • sysWorkspaceRoot = /workpaces/${node.getHostName()}
    This means that, when the path to these locations change, my successor will have to update two locations in QuickBuild. It is a small deal, and probably not worth the time it took to have this conversation.
robinshen ADMIN ·

Yes, they need to be maintained separately. This should be natural as they are actually independent settings.