How can I have a Jenkins pipeline build be trigger

2019-06-17 06:45发布

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:
    enter image description here 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.

3条回答
女痞
2楼-- · 2019-06-17 07:23

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.

查看更多
男人必须洒脱
3楼-- · 2019-06-17 07:26

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.

查看更多
我只想做你的唯一
4楼-- · 2019-06-17 07:34

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.

查看更多
登录 后发表回答