Kubernetes-Azure - adding a secret to a default serviceaccount via tasks in Azure Devops

Hi,
I want to add a secret to a default serviceaccount via tasks in azure devops but it does not work somehow (Kubernetes@1 task).
Thats my task:

    displayName: "add secret to serviceaccount default"
    inputs:
      connectionType: "Kubernetes Service Connection"
      kubernetesServiceEndpoint: "$(K8S_SE)"
      namespace: myOwnNamespace
      command: patch
      arguments: >
        serviceaccount default -p '{"imagePullSecrets": [{"name": "myImagePullSecret"}]}'```
I also tried multiple times to escape those quotes, but nothing works.
Thats the error message:
`error: unable to parse "'{imagePullSecrets:": yaml: found unexpected end of stream`
`##[error]error: unable to parse "'{imagePullSecrets:": yaml: found unexpected end of stream`

YAML is a superset of json so you need to escape your json properly so it fits in a string

Instead of trying to deal with the hell that is escaping json I would put the json (or yaml works fine as well) in a file and pass the file to the patch command instead, much less error prone

I tried multiple times to escape but it still did not work.
I will give try the method with the file passing

Do you have an example somewhere?

kubectl patch serviceaccount default -f /path/to/file.yaml

I think I have to pass the -p before the file path and use the artifact path where i have to save the json file… you wrote .yml. is .json ok?

-p is for patch inline. You use either -p or -f. If you use a file you do not use -p. You’re already specifying that it’s a patch by specifying the patch command.

.json is fine as well. I would use yaml as it’s more readable.

I see. I will give it a try now

Sorry it should be --patch-file and not -f

This worked. I did it with --patch-file and the json which i loaded into artifacts. Thank you