Q:Is a setup like this even possible? (Having the Jenkinsfile in a different repository than the repository you want to build).
A: Yes it is. You can specify Jenkins to pull in as many repos as you want.
Q: How would this work with polling? Would Jenkins still poll the proper repository for changes (one of the 30 different ones) or would it only poll the one repository containing the Jenkinsfile (this is not what I want obviously).
A: It would poll the scm that has the Jenkinsfile. This is important if you add changes to the Jenkinsfile. To remedy this (since you specified that this is behavior you do not want) you can add commit hooks or tokens in your repo that will essentially kick off the Jenkins job if the repo changes or when other circumstances happen (it varies depending on what repo hosting tool you're using, ie Github vs gitlab vs bitbucket etc). Otherwise you can also kick it off manually, but the automated way sounds like what you want.
As for implementation
This could be done with a multi-branch pipeline. Have one repository for all the variations of the jenkinsfiles, and each branch has the defining git scm <repo>
you mentioned. This way you can also have tokens/hooks in each so that if anything happens in the repo the corresponding job will autmatically be kicked off. The one minor set back to this is that you may have 30+ branches in the Jenkinsfile repository (or however many depending on the number of repos you have)
You can also certainly do what you mentioned above, having the Jenkinsfile job take a parameter for what repo it will use. My team has jobs like this where you specify the git_url
and git_treeish
(branch) so that you can point it to master or your personal fork for testing. The caveat to this is each build could have different results or artifacts and you'd have to check the build parameters on a per build basis to know what you are looking at if the repos make similar artifacts or results. (Ex: if you're running tests, your test result aggregation may not be clear because one build had results from Project/Repo A while another build had results from Project/Repo B etc). If you are forwarding artifacts/results to another job, this wouldn't be too much of a problem, you could base the post build procedure on the repo parameter you initially supplied.
If you comment with more details I can give you some code snippets or post a gist with examples if you need any.
checkout
is automatically included in polling unless you explicitly turn it off withcheckout poll: false, scm: ...
– Immediacy