getChangeNumbersTo(p4WorkspacePath, lastChange+1) retreives all changes *up to* the changeset used by the last build, +1. This is why I'm saying that you are assuming that the next changeset to build will always be the next number in the sequence, which is not always the case since you can have changes that are unsubmitted, shelved, or simply checked in outside of the job's workspace.