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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Edited

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

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

Like Oleksandr Kyrdan likes this

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']

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
Community showcase
Published in Confluence Cloud

🎨 Add some visual life to your templates

Hi Atlassian Community, My name is Avni Barman, and I am a Product Manager on the Confluence Cloud team. Based on feedback from you, we are giving admins more power to create templates that a...

119 views 1 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you