Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass flag to kubectl with Bitbucket Pipelines

guilherme_silva March 9, 2021

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

1 vote
guilherme_silva March 10, 2021

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
Oleksandr Kyrdan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 10, 2021

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
 

guilherme_silva March 10, 2021

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}"


 

guilherme_silva March 10, 2021

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
AUG Leaders

Atlassian Community Events