Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Multi-branch pipeline doesn't schedule tag jobs

I'm trying to get Jenkins' multibranch pipeline job to build tags in a similar manner to branches. In Jenkins 2.73 (not sure when the functionality was added), Multibranch projects can be configured to retrieve both branches and tags from the source repository. Initially I thought this would be perfect for my needs (my Jenkinsfile can now build development or production builds from the same place in Jenkins). Multibranch job with tags discovery configured

I have the build process itself up and running quite happily with a scripted pipeline, however my issue is that whilst the branch jobs pickup my triggers perfectly (Cron weekly) and are thus triggerable using the Git plugin's notifyOnCommit functionality (allows me to clean build weekly, but build on commit to the repo as well via a repo scan webhook), tag builds do not.

Has anyone else come across this? If so, have you found any reasonable way to resolve it?

Relevant snippet from my scripted pipeline (I tried with and without the overrideIndexTriggers setting):

properties(
  [
    pipelineTriggers(
      triggers: [
        cron('H 02 * * 7')
      ]
    ),
    overrideIndexTriggers(true)
  ]
)

Polling configuration from a branch job generated by the multibranch pipeline seems fine Jobs generated from tags by the multibranch pipeline do not receive the same configuration, bizarrely...

There is a note in the multibranch pipeline scan log that suggests that Tags will never be auto-scheduled:

Processed 8 branches
Checking tags...
  Checking tag testing
      ‘Jenkinsfile’ found
    Met criteria
No automatic builds for testing
Processed 1 tags
[Mon Oct 23 09:55:00 UTC 2017] Finished branch indexing. Indexing took 8.1 sec
Finished: SUCCESS

My project is docker based and I would like to run a release build weekly, to pull in any base-image changes etc.

Does anyone have any ideas about what I can do to get multi-branch projects to schedule tag builds?

like image 850
martsa1 Avatar asked Oct 23 '17 10:10

martsa1


People also ask

How do I schedule a job in Jenkins pipeline?

Add a Schedule to a Jenkins JobHead back to the job configuration and click the Build Triggers tab. Now, check the Build periodically box in the Build Triggers section. This will open the scheduling text area. Next, let's set the job to run every five minutes.

What is multi Branch pipeline in Jenkins?

What's a Jenkins Multibranch Pipeline? A multibranch job is simply a folder of pipeline jobs. For every branch you have, Jenkins will create a folder. So instead of creating a pipeline job for each of the branches you have in a git repository, you could use a multibranch job.


1 Answers

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

like image 194
Tommy Ludwig Avatar answered Jan 01 '23 23:01

Tommy Ludwig