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 to pass flag to kubectl with Bitbucket Pipelines

Edited

Hello everyone!

 

I'm using kubectl-run pipe on the version 1.3.3 to deploy my application to AKS. However I'm facing a problem on setting the application namespace, it's always getting the default namespace no matter what I pass to KUBECTL_ARGS. My pipe configuration looks like this:

- pipe: atlassian/kubectl-run:1.3.3
   variables:
      KUBE_CONFIG: $KUBE_CONFIG_PRD
      KUBECTL_COMMAND: 'apply'
      RESOURCE_PATH: 'deploy/WebApi/Deployment.yml'
      KUBECTL_ARGS: '--namespace ${ENVIRONMENT}'

No error is shown on logs and actually the pipe executes successfully. 

 

I could see on the source code that the KUBECTL_ARGS are concatenated with the command itself, but as I said on the AKS I'm always getting the default namespace.

 

This is a very important step to migrate my CI/CD from Jenkins to Bitbucket pipelines, so I really appreciate the help.

 

Best regards.

2 answers

To pass such argument to KubeCtl the pipe configuration must be like this:

- pipe: atlassian/kubectl-run:1.3.3
   variables:
       KUBE_CONFIG: $KUBE_CONFIG
       KUBECTL_COMMAND: 'apply'
       RESOURCE_PATH: 'deploy/WebApi/Deployment.yml'
       KUBECTL_ARGS:
             - "--namespace=${ENVIRONMENT}"
1 vote

Hi @guilherme_silva ,

Thank you for your question!

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

- pipe: atlassian/kubectl-run:1.3.3
   variables:
      KUBE_CONFIG: $KUBE_CONFIG_PRD
      KUBECTL_COMMAND: 'apply'
      RESOURCE_PATH: 'deploy/WebApi/Deployment.yml'
      KUBECTL_ARGS:
- "--namespace ${ENVIRONMENT}"


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

 

Cheers,
Oleksandr Kyrdan
 

Hi @Oleksandr Kyrdan

 

Thank you for the quick answer.

 

I just did the changes that you've suggested and now I'm getting the error bellow:

INFO: Configuring kubeconfig...
Error: unknown flag: --namespace staging
See 'kubectl apply --help' for usage.
✖ kubectl apply failed.

 

For the record, my pipe now looks like this:

- pipe: atlassian/kubectl-run:1.3.3
   variables:
       KUBE_CONFIG: $KUBE_CONFIG
       KUBECTL_COMMAND: 'apply'
       RESOURCE_PATH: 'deploy/WebApi/Deployment.yml'
       KUBECTL_ARGS:
             - "--namespace ${ENVIRONMENT}"


 

Hello @Oleksandr Kyrdan 

 

I just got what was wrong with the pipe configuration. To pass such argument to KubeCtl the pipe configuration must be like this:

- pipe: atlassian/kubectl-run:1.3.3
   variables:
       KUBE_CONFIG: $KUBE_CONFIG
       KUBECTL_COMMAND: 'apply'
       RESOURCE_PATH: 'deploy/WebApi/Deployment.yml'
       KUBECTL_ARGS:
             - "--namespace=${ENVIRONMENT}"

 

Thank you for the help. 

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

527 views 15 17
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