-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow running multiple commands #259
Comments
@bpoland thanks for raising this, we think it is a gap between how agent-stack-k8s parses pipelines yaml compared with the builkite backend. We can take a look at handling multiple commands in a command step too. |
OK thanks! I have been able to get it working like this in the mean time. It's a little weird but it seems to work 🤷
I definitely think supporting |
I take it back, have been seeing some issues with this approach where some of the later commands get dropped :( Not quite sure what's happening, still playing around with it. |
@bpoland have you tried using a format similar to what's in one of the sample pipelines: https://github.com/buildkite/agent-stack-k8s?tab=readme-ov-file#sample-buildkite-pipelines There are also a few samples in the tests: https://github.com/buildkite/agent-stack-k8s/blob/main/internal/integration/fixtures/artifact-upload-failed-job.yaml In particular, I would try I think the key thing to remember that shellisms like input redirection don't work in kubernetes. All you can do is run a command with some arguments and environment variables. So the |
Thanks, yeah I tried that initially but it seemed like bash was trying to run each word as a separate command maybe. For example when I use something like this:
Then when I run it I get a buildkite-agent usage message as though the arguments weren't passed to it properly :( |
OK I'm trying this and it seems to be working so far but it's a little annoying with the semicolons haha
Also just wanted to circle back to what you said It's still confusing to me that the input redirection sorta worked, sometimes 😕 |
@bpoland You're right that this is confusing. Looks like I confused myself too, so apologies for that. I was operating on the assumption that agent-stack-k8s mimics the behaviour of Let me clarify with an example. Without using agent-stack-k8s, if you create a YAML file like this: # my-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: alpine:latest
command: [ash, -xc]
args:
- |-
echo "Hello, Kubernetes!" > test.txt
ls -lA test.txt
false
cat test.txt and run it in a k8s cluster with kubectl apply -f my-pod.yaml You should be able to observe that each line is run in sequence, which is what I expect if the
Indeed, when I tested this and ran kubectl logs -f pod/my-pod the output was:
The test fixtures I linked previously had a similar syntax and as the tests behaved as expected, I thought I had verified that agents-stack-k8s behaved in the same way. But now it seems that the tests were accidentally passing, and the behaviour is a little different, Looking deeper into the code, I now see that we do some mangling of the The agent itself will run the contents of I think we can spend some more time finding a precise explanation to the usual behaviour you've observed, or we can use this knowledge to conclude that the setting the agents:
queue: kubernetes
steps:
- label: Test command without args
plugins:
- kubernetes:
podSpec:
containers:
- image: alpine:latest
command:
- |-
buildkite-agent annotate "This is a test annotation"
echo "another thing" | tee artifact.txt
buildkite-agent artifact upload artifact.txt |
Now, back to the original question of allowing the usual Buildkite Pipeline YAML syntax where a step:
- command:
- buildkite-agent annotate "This is a test annotation"
- echo "another thing" | tee artifact.txt
- buildkite-agent artifact upload artifact.txt I think there is going to be a some confusion between this and the expectation in Kubernetes that I think, in agent-stack-k8s, you can achieve running multiple commands chained together, as demonstrated at the end of my previous comment. I'm hesitant to introduce two different ways of doing the same thing. Let me know if your ask is to be consistent with the non-k8s behaviour, or to just get multiple commands working in a single step. If it's just the latter, I should just fix up the documentation. |
Oh wow, I didn't think to try just setting I guess the only downside to this approach is that each command is not grouped separately in the output, making it a little more difficult to tell where the output from one ends and the next one starts (depending on the commands being run obviously). I tried using the bash |
Coming back to the original request (multiple commands), #371 will change |
Thanks, yes that does look like it will solve this problem -- excited to try it out! |
Going to call this one fixed! |
Hi, I'm just getting started with agent-stack-k8s and wondering if it would be possible to allow running multiple commands instead of just one on the containers? I realize the existing setup is modeled after kubernetes pod spec which isn't designed for that but it appears that under the hood, the command we specify is actually getting executed after the agent starts.
I've tried playing around with yaml multiline strings and here-docs but that seems to cause some weirdness with tokenization and seems like every word gets run as its own command. Another option I thought of was to copy in a script file and just execute that, but it's a little convoulted.
It would be awesome if we could just replace
command
withcommands
similar to the native step (https://buildkite.com/docs/pipelines/command-step#command-step-attributes) and provide a list of commands to run. Would that make sense or am I missing some obvious way to do this?The text was updated successfully, but these errors were encountered: