How do I run "kubectl delete job/rolling-update" in a Bitbucket pipeline?
Asked by gmlewis:

In a bitbucket pipeline, I'm trying to run the command: "kubectl delete job/rolling-update", and tried this:

```
- step:
    name: Delete any previously-existing rolling-update jobs - OK to fail
    script:
      - set +e
      - pipe: atlassian/kubectl-run:1.3.3
        variables: 
          KUBE_CONFIG: $KUBE_CONFIG
          KUBECTL_COMMAND: "delete" 
          KUBECTL_ARGS: "job/rolling-update" 
      - set -e 
      - sleep 10
```

however, the error that I get is this:

    error: You must provide one or more resources by argument or filename.
    Example resource specifications include:   
        '-f rsrc.yaml'   
        '--filename=rsrc.json'   
        '<resource> <name>'   
        '<resource>'
    ? kubectl delete failed.

and I thought I was providing the resource as described in the last line.

EDIT: I also tried:

```
KUBECTL_ARGS: "['job/rolling-update']"
```

and that didn't work either.

Note that running this command locally works fine, so the problem is with passing the arguments to the pipe command.

Does anyone know how to fix this issue?

While I'm here, it would be nice to have an example of this in the documentation for this pipe instead of giving all examples using only "apply":

[https://bitbucket.org/atlassian/kubectl-run/src/master/README.md](https://bitbucket.org/atlassian/kubectl-run/src/master/README.md?)

Thank you!


Answers:
author: Oleksandr Kyrdan
body: Hi [@gmlewis](/t5/user/viewprofilepage/user-id/4295137) ,

Thank you for your question!

Please, provide KUBECTL_ARGS as a YAML list, not as a string:

```
- step:
    name: Delete any previously-existing rolling-update jobs - OK to fail
    script:
      - pipe: atlassian/kubectl-run:1.3.3
        variables:
          KUBE_CONFIG: $KUBE_CONFIG
          KUBECTL_COMMAND: "delete"
          KUBECTL_ARGS:
            - "job/rolling-update"
```

or you could provide full command into KUBECTL_COMMAND:  

```
- step:
    name: Delete any previously-existing rolling-update jobs - OK to fail
    script:
      - set +e
      - pipe: atlassian/kubectl-run:1.3.3
        variables: 
          KUBE_CONFIG: $KUBE_CONFIG
          KUBECTL_COMMAND: "delete job/rolling-update" 

```

<br />

We'll investigate this case to prevent such pipe's behavior and notify you.  

<br />

Cheers,  
Oleksandr Kyrdan  

comments: author: gmlewis
body: Thank you, [@Oleksandr Kyrdan](/t5/user/viewprofilepage/user-id/2885705) !


author: gmlewis
body: I think the problem is in the \`pipe.py\` script on lines 110-111:

<https://bitbucket.org/atlassian/kubectl-run/src/e53754cb58a4b473d63547da7cca4b86d577505a/pipe/pipe.py#lines-110:111>

```
result = subprocess.run(['kubectl'] + cmd.split() + list(self.get_variable('KUBECTL_ARGS')) + debug, stdout=sys.stdout)
```

No matter what I pass in for \`KUBECTL_ARGS\`, the \`list()\` Python function is going to dice it up into a list of individual characters, like this:

```
?>>> list("job/rolling-update")
['j', 'o', 'b', '/', 'r', 'o', 'l', 'l', 'i', 'n', 'g', '-', 'u', 'p', 'd', 'a', 't', 'e']
```

comments: author: gmlewis
body: Now that I dug further into the implementation of the Pipe class, I think my description above is not correct. [@Oleksandr Kyrdan](/t5/user/viewprofilepage/user-id/2885705) - I can delete this comment if you would like me to.


Tags: bitbucket-pipelines

cloud

kubernetes