In my opinion this is not a duplicated of JENKINS-33046
I have a very similar request as you do. In my case the main issue is with Android release in Google Play. Our current version is 2.2.21 and build number is 331, the versionCode becomes 202213312 (20221 is the version, 331 is the build number, 2 is the architecture) but the maximum value allowed in Google Play is 2100000000, which means that we are either limited to 3 digits build number if we reach version 10.x.x or to 4 digits if we assume we will stick to single digit major version.
Thus, as you do, we need to be able to reset the build number back to 1 when the major or minor version increases. Ideally, as you pointed out, this should be done from the JenkinsFile. I am not a Jenkins expert but I don't think that this is possible at the moment.