Remove targeting rules

I have a pipeline that runs a series of quick tests in dedicated LXD containers;

At the end of this pipeline, the second-to-last step launches a virtual machine with parameters queue=$BUILDKITE_BUILD_NUMBER set via AWS tags. The buildkite agent launches successfully in this ephemeral virtual machine.

The final step dynamically creates a pipeline like this:

    # meant to be piped to buildkite-agent
    echo "
steps:
  - label: \"k3s integration test\"
    commands:
      - ./run-k3s-tests.sh
    agents:
      queue: $BUILDKITE_BUILD_NUMBER

The new steps are added successfully, but the agent targeting from the previous steps is added to, not replaced. So the step hangs.

image

I suppose I could add an AWS tag container_image: ubuntu-2110-ci to the ephemeral VM. But is there a better way?

What I’d like is to continue this pipeline in a different machine, spawned on command. I’ve already pre-baked an AMI with buildkite that accepts tags from EC2 tags.

Is there a better way to accomplish this?

Hi @coleman

Firstly welcome to Buildkite community and thank you for reaching out to us with your questions.

Reviewing your pipeline definition, we can see that you have agent targeting rule defined at pipeline level rather than at a step level. Because of this the agent target rule of “container_image: ubuntu-2110-ci” is also getting appended to this dynamic pipeline step as well.

Any reason for defining agent target rule “container_image: ubuntu-2110-ci” at pipeline level in earlier step ? if no specific reason then, please change that to step level like you have for target rule “queue: $BUILDKITE_BUILD_NUMBER” to avoid appending of target rules from previous steps

The reason for container_image is to select the appropriate build environment. All our pipelines have this attribute set to one of a few different OS versions.

@coleman Yes, but you can define the agent target rule at the step level instead of pipeline level so that way when you do dynamic pipeline with a step that has agent target rule then earlier steps agent target rules wont get appended.

This was the answer I was looking for: adding targeting at the step level, which isn’t something we’ve needed to do until now.

image

That changed removed the “global” targeting, and my dynamically generated step doesn’t set global targeting either. Instead, we set a dynamically generated queue attribute.

    # meant to be piped to buildkite-agent
    echo "

steps:
  - label: \"k3s integration test\"
    commands:
      - echo \"HELLO WORLD\"
      - k3s kubectl get nodes
    agents:
      queue: $BUILDKITE_BUILD_NUMBER
"

@coleman Yes, that is what I was also referring to when I was saying setting agent target rule at step level instead of pipeline level so next steps will not get target rules appended.

Happy to see that it solved the issue for you. Thank you again for being part of Buildkite community.

1 Like