Don't build older tags (via Basic Branch Build Strategies or similar)
danielluke opened this issue · 10 comments
What feature do you want to see added?
I've got a Jenkinsfile that does a daily run updating some dependencies and then running my test suite, so I hopefully know if an upstream change will eventually impact my application.
I do this via cron('@daily') trigger plus a stage that only runs when triggeredBy 'TimerTrigger'. This works well except that I also use tags to note my release versions (and trigger some deployment actions). With 'Discover tags' turned on they all end up rebuilding daily against updated dependencies even though I have Basic Branch Build Strategies Plugin installed and configured to ignore tags older than 7 days. I can turn off 'Discover tags', but then when { buildingTag() } doesn't work to run my release stage.
I can add when{} blocks to each of my stages to avoid this (and go back an re-tag previous releases with an updated Jenkinsfile), but ideally I'd like to be able to keep the Jenkinsfile logic simpler and just avoid the unwanted builds.
https://issues.jenkins.io/browse/JENKINS-64810 seems to indicate that changes are needed in bitbucket-branch-source-plugin, but #441 seems to indicate that it should work.
Upstream changes
No response
Can you use cron(condition ? "@daily" : "")
and make the condition check for a tag somehow?
Probably - but then I have to go back and move all of the previous release tags to a new commit that has that change.
I doubt this can be implemented in bitbucket-branch-source-plugin in such a way that the tags remain discovered but aren't built again.
TagBuildStrategyImpl.isAutomaticBuild checks the age of the tag and is called by BranchBuildStrategy.automaticBuild, which is called by MultiBranchProject.isAutomaticBuild. But if you have a cron trigger on the job, then I think it will trigger the job directly (Trigger.checkTriggers, TimerTrigger.run) and not care about the MultiBranchProject.
Perhaps you could hack this by writing an unsandboxed Groovy script that deletes the cron trigger from the ParameterizedJob.getTriggers() map of each tag job even though the Jenkinsfile still claims that the trigger should be there, and then saves those changes. I think the cron trigger would then stay away. Alternatively, you could try makeDisabled, or add something that overrides WorkflowJobProperty.isBuildable to return false. Those things don't depend on bitbucket-branch-source-plugin, though.
I'd actually be happy if the older tags aren't discovered/disappear (that's the behavior I'd expect with Basic Branch Build Strategies Plugin set to ignore tags older than 7 days).
Well, those are build strategies, not discovery strategies.
Do you want the tag jobs to be built daily for the seven days?
Well, those are build strategies, not discovery strategies.
Right, just confusion on my part when I initially set this up.
Do you want the tag jobs to be built daily for the seven days?
I don't need them to, but it's OK if they do.
The tag discovery filter could be implemented as a class similar to WildcardSCMHeadFilterTrait (javadoc, source). Override SCMHeadPrefilter.isExcluded (source) to recognize TagSCMHead (source) and check the timestamp. The new trait would not depend bitbucket-branch-source-plugin, and it would even be able to work with version control systems other than Git, if they provide timestamps of tags. I think it should not be added to bitbucket-branch-source-plugin. Instead, it should be published as a new plugin or added to scm-api-plugin.
The list of SCMTrait extensions doesn't seem to include a trait like that yet.
On the other hand, an easier solution might be to put a conditional expression into the cron trigger like I suggested, and use a filter-by-name trait to exclude all the older tags that have unconditional cron triggers.
For my purposes, I've adopted the conditional cron + wrote a script to update my previous tags (I'd /like/ to never change something once tagged, but it seems like a reasonable solution for my immediate issue).
Bitbucket Aged References SCM Filter might have worked. Its description mentions "references (branches and pull requests)" but support for tags on Bitbucket was added in jenkinsci/scm-filter-aged-refs-plugin#11. This feature was added after the latest release 0.2.0, though.
I'm not sure why that plugin is not listed as extending SCMTrait. Its javadoc is missing too.