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.

Detect if shelved changelist is empty and fail build #3517

goydex ·
We use the p4 repository feature on QB 6.1.8.

We have a manual build process where someone specifies a shelved CL and the server will unshelve the files and perform the build. We want the system to fail if the shelved CL has no files in it. We would usually detect errors on the step, but for p4 checkout there isn't such an option.

How is it suggested to accomplish this?

Thanks
  • replies 7
  • views 4775
  • stars 0
robinshen ADMIN ·
In post execute condition of the checkout step, use below script:
groovy:
def repo = repositories.get("perforce repo name");
if (repo.getShelveSupport() != null && repo.getShelveSupport().getActualShelvedChanges() == null || repo.getShelveSupport().getActualShelvedChanges().isEmpty())
throw new com.pmease.quickbuild.QuickbuildException("No shelved changes to build");
goydex ·
This isn't working. This if failing if NO changelist is specified, but not if a specified CL is empty (contains no shelved files).

What we want is:

1. Do not fail if no shelved CL is specified (this okay, sometimes we build regression builds this way)
2. Fail if shelved CL is specified, but its contents is empty. (Multiple CL's can be specified by listing them between commas)
3. Do not fail if shelved CL's all contain files.

Thanks
robinshen ADMIN ·
Thanks for the clarification. I filed a ticket to address this:
http://track.pmease.com/browse/QB-2705
DTakz ·
Approximately how long would it take for this ticket to be resolved or to be added on QB?
robinshen ADMIN ·
For urgent features, we can put them into next one or two patch releases which should be available in one or two weeks. If you feel this is important, please vote for the issue.
jamuirhead ·
You can make a call to 'p4' in the build's Pre-Queue event script or within a build script-type step. Parse the output using RegEx. If the CL is empty, throw a QB exception. Sample:

for (changelist in vars.get("p4_shelved_changelist").asList()) {
output = util.readOutput("p4 -C utf8 -c ${repositories.get("p4Repo").getClientName()} -p ${repositories.get("p4Repo").getPort()} -u ${repositories.get("p4Repo").getUserName()} -P ${repositories.get("p4Repo").getTicket(repositories.get("p4Repo").getUserName(), repositories.get("p4Repo").getPassword())} describe -s -S " + changelist)

// Check for files in the changelist
m = output =~ /Shelved files \.\.\.([\w\W]+)$/;
if (! (m && m[0][1].trim() != "") )
throw new QuickbuildException("Shelved changelist does not contain any files: " + changelist)

}

This has been used successfully with QB 5.1. I'd assume it would also work with QB 6.x, but have not tested it.

Cheers.
jamuirhead ·
EDIT:

This You can make a call to 'p4' in the build's Pre-Queue... should be: You can make a call to 'p4' in the configuration's Pre-Queue...

Also, substitute "p4Repo" for the name of your Perforce Repository.