Am I being overly ambitious and just need to resign myself to the fact
that I need to block the entire Jenkins job when a resource is locked by
another job, and not just block the individual build step?
I've discovered that ResourceActivity is close to what I require, the problem is that once the build is underway I cannot update the resouce that I am trying to lock.
Ideally in the perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) method I would:
- Set the resource that I want to lock to reserve its place in the queue
- Notify Jenkins that it needs to update the resource locks for this build - ie Jenkins would call
getResourceList() again - Check if any other jobs already have the resource locked and sit waiting wait unit the locked resource is available again before proceeding
public class SelectApplicationBuilder extends Builder implements ResourceActivity {
...
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws IOException {
...
}
@Override
public ResourceList getResourceList() {
System.out.println("==================BuildMaster Application Resource " + this.applicationId);
ResourceList list = new ResourceList();
Resource r = new Resource("BuildMaster Application " + this.applicationId );
list.w(r);
return list;
}
// ResourceActivity
@Override
public String getDisplayName() {
return "BuildMaster Application Resource";
}
}