简体   繁体   中英

How can I make a Jenkins build for a GitHub repository be triggered by a push to a different repository?

I have a GitHub repository (call it X) for a Python code package, and a separate GitHub repository (call it X-tests) that contains the tests for that package (they're separate repositories because the one containing the tests is private so that it can run other private code). I would like to make it so that when someone pushes to the X repository, Jenkins will run the tests from the X-tests repository, and then do some other stuff related to the X repository (eg making a pip wheel).

The only way I can think of to do this is to have three separate Jenkins jobs:

  1. a job that does nothing, whose GitHub repository is X, where builds are triggered by pushes to X
  2. a job that runs the tests, whose GitHub repository is X-test, where builds are triggered by completion of job 1
  3. a job that makes the pip wheel etc., whose GitHub repository is X, where builds are triggered by completion of job 2

Is there any simpler way to do it?

I think this is a pretty standard approach to implementing a simple build-test-posttest pipeline. Job 1 is name -commit-stage, job 2 is name -test-stage or name-integration-stage and a third job for your pip-wheel.

You can see a more complex pipeline in the build pipeline jenkins plugin.

Check if your third job should be using job 1's artifacts instead of repository X. This will bring atomicity to your pipeline as someone could push something to your repository X while a job has already started. The Copy Artifact Plugin is useful for that, or you can just reference the local job 1 workspace as a source of your job 3 (as a parameter in a build step).

You also need to make sure that changes to repository X-Tests should be pushed before changes to repository X, as job 2 may use code in repository X-Tests that is not in sync with repository X, leading to test failures.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM