Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

gmlewis March 8, 2021

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 

Thank you!

2 answers

1 accepted

2 votes
Answer accepted
Oleksandr Kyrdan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 9, 2021

Hi @gmlewis ,

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"


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


Cheers,
Oleksandr Kyrdan

gmlewis March 9, 2021

Thank you, @Oleksandr Kyrdan !

Like Oleksandr Kyrdan likes this
0 votes
gmlewis March 8, 2021

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']
gmlewis March 9, 2021

Now that I dug further into the implementation of the Pipe class, I think my description above is not correct.  @Oleksandr Kyrdan - I can delete this comment if you would like me to.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events