Can Jenkins job watch one repo for changes, to trigger a build on another repo?

不羁岁月 提交于 2020-01-05 06:55:15

问题


Using Jenkins and pipelines;

I have one repo which drives deployments and cloning its Jenkinsfile should kick off a new build; but I need the jenkins job which wraps it to watch another repo representing the site (not its build process), to watch for and build changes to the site, expected to change often, rather than the build process which hopefully will soon be stable and not subject to much additional change.

Can anyone please advise me how it is I would accomplish this feat?


回答1:


Use the jenkins build step.

In the repo experiencing the changes, have its Jenkins job kick off a https://jenkins.io/doc/pipeline/steps/pipeline-build-step/ for the repo you want to build. You can configure the build step to either wait or not wait for the result of the kicked off job.

build(job: "org/${jobName}/${BRANCH_NAME}", 
    parameters: [
        new StringParameterValue('ENV', env),
        new StringParameterValue('ENV_NO', env_no),
    ],
    propagate: false, 
    wait: false,
)



回答2:


Usually I‘d recommend to have the Jenkinsfile in the very same repository like your source code. Only that way you will have a combined history so it‘ll be much easier to reproduce an older build from - let’s say - one year ago.

However if you still want to go for the separation: The git/checkout steps will usually have the possibility to add a hook in Jenkins so the job will get triggered automatically on changes.

If I did understand your use case correctly the Jenkinsfile will go into stable state. If it’s stable it won’t change. When there are no changes it won’t trigger the job, right?

If that still is not enough I think I would need more details on what you’re trying to achieve and why.



来源:https://stackoverflow.com/questions/50091626/can-jenkins-job-watch-one-repo-for-changes-to-trigger-a-build-on-another-repo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!