Run multiple repositories in a single pipeline

I have a repository to run automated tests that is separate from the source code repository.
On the source code repository buildkite pipeline.yaml, I would like to include a step to trigger this other repository to run the tests and check if tests are successful before it gets to the next step.
Bitbucket pipeline has a similar extension called Pipe Bitbucket Pipes integrations | Bitbucket

Hey @ebanster :wave:

It looks like you could use the trigger step to start another pipeline against a different repository. The docs on how to use that step are at Trigger Step | Buildkite Documentation.

You can run it synchronously so the current pipeline will wait for the triggered one to finish and continue on success or stop on failure. You can also run it async, but that means it won’t wait for it to finish.

Hope that helps

1 Like

Thanks for this @jarryd . Sorry if I’m missing it from the documentation you provided but I can’t find the reference to the other repository (I can only find a branch but not the URL of the repo). Or is it one of these?


No worries :+1:

A trigger will create a new build on a pipeline. So you would need to create another pipeline and configure that one against the repo you are wanting to build. Then in your pipeline that is doing the triggering you won’t have to pass the repository because its configured at the pipeline already.

So, you would have pipelineA that is building repoA and pipelineB that is building repoB.
Then the steps in pipelineA have a trigger step targeting pipelineB. Eg: here you can see it trigger pipelineB on the same branch and commit (which if it is a different repo, might not match repoA but hopefully you can get the gist)

- trigger: pipelineB
    message: "${BUILDKITE_MESSAGE}"
    commit: "${BUILDKITE_COMMIT}"
    branch: "${BUILDKITE_BRANCH}"

Is this the correct illustration?

… and then inside the test-pipeline.yml, I will have the following?

      BUILDKITE_PULL_REQUEST_REPO: "...test-repo.git"

Yeah I think that makes sense :+1:

I’m not sure those env vars would be appropriate here. Are you building on PRs? And do those PRs on each separate repository line up each time? Ie do you create a PR on “build repo” with #x and then another one on “test repo” with #x or would it be a different number?
My gut says to not pass these in this example since your first question said they are different repos.

I guess my question is if I don’t have the BUILDKITE_PULL_REQUEST_REPO then how do I know which repo (in this case, test-repo or repoB) that I need to trigger?
If both the build and test pipelines are inside the build-repo or repoA then what is the variable that I need to point to the other repo’s URL?

Oh right okay. I was mislead by your original question.

This is still possible. You can have multiple pipelines per repository, ie if its a monorepo. You can set up a webhook to trigger only one from GitHub, then within that one (pipelineA) you trigger pipelineB like we’ve said above. But both pipelineA and B both have configured repoA as their repository, but only pipelineA is directly built from push events on GitHub and pipelineB is triggered from pipelineA.

In that case you could pass those variables along because its the same repo.

You might also want to check out this plugin to handle monorepo pipelines: GitHub - chronotc/monorepo-diff-buildkite-plugin: Run separate pipelines for each folder in your monorepo. This might be a nicer way to set up what you want.

Have a play and see how you go

Hi @jarryd sorry for confusing you further and thanks for being patient so far. We actually don’t have a monorepo but 2 separate repositories for our microservice / component and our e2e tests.
First off, the reason my thread title is like that is because that is how the Bitbucket pipeline works. So for example, I have a bitbucket-pipeline.yaml on my microservice repository. On that single pipeline, it triggers the other e2e test repo to run and wait first with the following:

  - pipe: atlassian/trigger-pipeline:5.0.0
      BITBUCKET_USERNAME: '<service account>'
      BITBUCKET_APP_PASSWORD: '<service account password>'
      REPOSITORY: '<url to the other e2e test repo (e.g. git@...git)'
      WAIT: true

This is exactly what I want to achieve where the pipeline is on the microservice repo and the step includes triggering the other test repository and waits for the tests to finish before it goes to the next step.

Here’s the reference: Bitbucket Pipes integrations | Bitbucket

Oh okay :+1:

That goes back to this answer then to just trigger another pipeline: Run multiple repositories in a single pipeline - #4 by jarryd.

You don’t need to tell the trigger what repo because its configured against the pipeline you are triggering already. And in each repo you will need a .buildkite/pipeline.yml file which each respective pipeline the steps it needs to run.
The steps in repoA (microservice) would have the trigger step in it as above. The steps in repoB (e2e tests) would run the test suite you have.

Thanks @jarryd but I’m still confused.

Going back to my illustration above, how would the test pipeline know that I need to run the test repo’s .buildkite/pipleine.yml file?

If my understanding is correct from your explanation, it should be something like this?

… but again, my question is how would my build pipeline know that it needs to trigger the test pipeline sitting on another repo?

Or is buildkite smart enough to know which pipelines to run regardless of which repo it sits against?

No probs.

On each pipeline, you configured a specific repository that may have a .buildkite/pipeline.yml file (you can find more info on how the pipeline upload works here buildkite-agent pipeline v3 | Buildkite Documentation)

When you do a trigger step (ie: create a new build on another pipeline), the build is going to check the configured repository from that “triggered” pipeline, and, therefore its corresponding yml file.

So you have 2 of everything here:

  • 1 repository that has the tests in it
    • 1 pipeline for this repository
    • this repository has a .buildkite/pipeline.yml file with steps that run those tests
  • 1 repository for the source code (that is being tested against)
    • 1 pipeline for this repository
    • this repository has a .buildkite/pipeline.yml file in it which uses a trigger step to trigger the pipeline above which goes off and runs the steps for that pipeline

I’m not sure if you have given this a test try yet but I believe if you have a play around it will become apparent how it works. You can sign up for a free account and have 30 days trial to kick the tyres

My mistake @jarryd . I got it now and its working as you explained. It initially got me confused as it works differently from the bitbucket pipeline but I think buildkite is smarter in this case.

Off the top of your head, I was just wondering if conditional statement like this would work (not sure if its a correct yaml syntax with the trigger command):

  - label: '🧪 Run tests'
    if: build.branch == 'master'
    trigger: 'test-pipeline'

I wanted to run it only against master branch as right now, it is running with every branch.

Hey @ebanster!

Yup, that should work just fine. You can test it out :blush:


1 Like

Thanks @paula I will try it out.

Sorry while we’re on this same thread, can I just verify this scenario:

  - label: "🧪 End to End Tests"
    if: build.branch == "master"
    trigger: "test-pipeline"
        EMAIL: "${EMAIL}"

I have declared EMAIL and PASSWORD as CI variables in the build pipeline’s Build steps. If my test pipeline contains these variables and have different values, will it override those values with the one I set on the build pipeline? Example below:
build pipeline
PASSWORD: 123456

test pipeline
PASSWORD: abc123

When the test pipeline is triggered, it will run against / 123456 instead.

That’s right, the env you specify on the trigger step will override the defaults you have set in the test-pipeline

1 Like

Thanks @jarryd and @paula you both are stars! Worked like a charm!