I have a repository that does not contain a Jenkinsfile - and I have no way of influencing the repository itself. This means I can neither add nor alter any files to or in the repository (In this case, its the Qt repo).
What I want to do is create multiple Jenkinsfiles, that are each configuring and building the Qt library for a different target, or run different additional scripts.
All these Jenkinsfiles will be collected in a different repository.
Now, my problem is how to create a pipeline job, that gets triggered, as soon as there are changes in the Qt repository, but uses a Jenkinsfile from the other repository.
Research left me - as far as I can see and according to these posts - with two options:
Adding both repositories to the Definition section - something along the lines of this:
Unfortunately, this does not work for me, as both repositories would still need a Jenkinsfile. Further, I cannot specify a different branch for each repository, so I cannot listen to a specific Qt Version branch.The second (well, probably the only) option I see, would be to create a freestyle Jenkins job, that solely listens to the Qt repository and triggers a build of the pipeline job on a change as its only action.
I reckon, that the second approach would work for me, but what I want to know, is whether there is any plugin, configuration option or whatever that I missed that can solve this in a cleaner way, or whether the above is the way to do it.
Why don't you create a Jenkins Freestyle Job that monitors the QT repo using the regular "Poll SCM" method?
Then have that Freestyle job kick off one or more of your Jenkins pipeline jobs.
You would have the pipeline jobs point at the SCM where the pipeline "jenkinsFile" groovy scripts live (the repos you control).
Inside the pipeline code, you can use a pipeline SCM DSL step to pull code from the Qt repo (the one not under your control) then do all the building, testing or whatever.
You can pass the URL and revision of the Qt Repo into the pipeline as a parameter from the polling job.
Did you think about a webhook that triggers the Jenkins job from your Git server? This way you can have arbitrary repos trigger your build and reduce the traffic on the Git server caused by the periodic poll from Jenkins.
The principle behind it is that Jenkins provides a URL for your build job (e.g. http://your-jenkins.domain/job/JOBNAME/build?token=TOKEN
) that starts your job. Git on the other hand can register a so called hook that is triggered whenever a push is made to the repository. Adding a HTTP request to your Git hook will trigger the Jenkins job every time someone pushes to your repository.
This SO Post explains how to set up such a hook with any Git server. There are also tutorials for Gitlab and Github.
You can configure a build trigger, to check if there are changes in the repository: Build Trigger -> Poll SCM. There you can configure a schedule:
For example * * * * *
to check every minute or H * * * *
to check hourly.
来源:https://stackoverflow.com/questions/41116169/how-can-i-have-a-jenkins-pipeline-build-be-triggered-from-a-repository-with-no-j