Is there a way to automatically build tags using the Multibranch Pipeline Jenkins plugin?
Asked Answered
H

3

24

After creating a Multibranch Pipeline in Jenkins I can easily tell it to poll for changes or additions of any branches and it will automatically create jobs for and build those branches. I told the Multibranch job to also discover tags, so it automatically creates jobs for each tag, which is great.

Is there a clean way for Jenkins to automatically build those tags as well, instead of me having to trigger them manually? As you can see below, the job for the tag is there, but I have to manually build it.

enter image description here

Herwick answered 6/11, 2017 at 22:5 Comment(0)
S
26

I would have commented with this, but I don't have enough reputation. I believe this is a duplicate of Jenkins Multi-branch pipeline doesn't schedule tag jobs. See my answer there, copied below.

In short, if you build and install the Jenkins plugin available at https://github.com/AngryBytes/jenkins-build-everything-strategy-plugin then you can add a Build Everything strategy which will automatically build tags.


Not automatically triggering a build for discovered tags seems to be by design according to JENKINS-47496. Stephen Connolly offers an explanation and suggestion for what you might do:

Stephen Connolly added a comment - 6 days ago

Tags are not built by default (because otherwise you could have a build storm when checking out a repository) and worse, the order tags will be built in is unpredictable... and you might have a Jenkinsfile that deploys to production when a tag is built.

There is an extension point in branch-api called BranchBuildStrategy which - if implemented - will allow deciding whether to build tags.

See https://github.com/jenkinsci/github-branch-source-plugin/pull/158#issuecomment-332773194 for starting point on how to create such an extension plugin... I believe there is some work on one at https://github.com/AngryBytes/jenkins-build-everything-strategy-plugin

Sensational answered 16/1, 2018 at 7:46 Comment(0)
H
9

As @tommy-ludwig says, you need an additional plugin providing a Build Strategy ; since his original post, Stephen Connolly has published the Basic Branch Build Strategies Plugin which among others provides a strategy to build tags.

Haldi answered 8/3, 2018 at 8:7 Comment(0)
D
3

If, like me, you don't care if the tags show up on a separate tab, you just want the tags to be visible when your various branches are being built (which implies that your tags will be built), then do this:

In your multibranch pipeline's configuration, go to "Branch Sources", "Git", "Behaviors", and add "Advanced clone behaviors". By default, when you add this you will see that "Fetch tags" is checked. Voila!

Dibromide answered 4/10, 2018 at 20:26 Comment(2)
I have "Fetch tags" checked but tags are still in their separate tab and aren't built automatically. Anything else I need to do?Sieber
Thank you - this fixed a problem I was having with a job that automatically derives a version number (via setuptools-scm) for Python packages it builds, with a version derived from the git tag :)Sconce

© 2022 - 2024 — McMap. All rights reserved.