# Inserting a step into the middle of a base pipeline

**URL:** <https://forum.buildkite.community/t/inserting-a-step-into-the-middle-of-a-base-pipeline/3378>\
**Category:** Pipelines\
**Created:** [December 1, 2023, 1:01am UTC](https://forum.buildkite.community/t/inserting-a-step-into-the-middle-of-a-base-pipeline/3378 "2023-12-01T01:01:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjwu15](https://avatars.discourse-cdn.com/v4/letter/c/5f8ce5/32.png) [@cjwu15](https://forum.buildkite.community/u/cjwu15)\
**Post date:** [December 1, 2023, 1:01am UTC](https://forum.buildkite.community/t/inserting-a-step-into-the-middle-of-a-base-pipeline/3378/1 "2023-12-01T01:01:59Z")

</div>

I have several pipelines for deploying services that run a base pipeline, like so:

```auto
env:
  SERVICE_VAR: foobar
  ...

steps:
  - label: ":pipeline: Upload base pipeline"
    command: buildkite-agent pipeline upload pipelines/base.yml

```

Where the base.yml looks like:

```auto
steps:
  - label: "..."
    command: ...

  - wait

  - label: "..."
    command: ...

  - wait

...

```

Is it possible to have one of my service pipelines inject a step into the middle of the base pipeline while still being DRY? The base pipeline is large enough that it would be impractical to create an anchor for each step. Can sequences of steps be anchored and referenced as single steps in my service pipeline?

---

<div class="post-metadata">

**Author:** ![james.s](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/james.s/32/1305_2.png) [@james.s](https://forum.buildkite.community/u/james.s)\
**Post date:** [December 1, 2023, 1:43am UTC](https://forum.buildkite.community/t/inserting-a-step-into-the-middle-of-a-base-pipeline/3378/2 "2023-12-01T01:43:13Z")

</div>

Hey @cjwu15!

Hope you’re well - and welcome to the Buildkite Forum! 👋

In the case of DRY - you’re certainly able to chain together uploads - pending that the pipeline that is to be _further_ inserted within your `base.yml` is stored within said repository also (or this might be another generator script that creates the YAML that is to be further uploaded. Of course, if this further uploaded pipeline uploads _even more_ pipelines dynamically in a ternary relationship, it’ll still be actioned through that very first step that uploaded the first pipeline.

Given that you said you only want this to be run by a specific service pipeline, you’d likely use [build variables](https://buildkite.com/docs/pipelines/conditionals#variable-and-syntax-reference-variables) within a conditional: and likely `pipeline.slug` to only upload the pipeline chain based on builds coming from a specific pipeline (this could also be a script to run that will produce the YAML to be uploaded, and `service-pipeline.yml` can have even more uploads in it):

```auto
steps:
  - if: pipeline.slug == "<service-pipeline-slug>"
    key: uploader
    command: "buildkite-agent pipeline upload .buildkite/service-pipeline.yml"

```

Of course, more generic ways can be had with this - including potentially feeding the uploads in [hooks](https://buildkite.com/docs/agent/v3/hooks#hook-locations). Depending on the use case, you could have an agent level hook that’ll upload a specific pipeline, though a conditional like the above will be needed in that hook’s script just so it runs on specific builds (and avoiding an upload loop).

Theres even more of a wider approach with [pipeline templates](https://buildkite.com/docs/pipelines/templates), but this is a Enterprise plan (would standardise the pipeline YAML for one/many pipelines)

Hope the above does help!
