jenkinsci / kubernetes-cli-plugin

Allows you to setup kubectl to access Kubernetes clusters from your Jenkins jobs.
https://plugins.jenkins.io/kubernetes-cli/
Apache License 2.0
89 stars 48 forks source link

Using $VAR for namespace is not working #73

Closed MLukman closed 4 years ago

MLukman commented 4 years ago

Expected Behavior

The plugin should be able to consume $VAR for all configuration keys

Actual Behavior

The plugin works when only "Kubernetes API endpoint", "Cluster name" and "Context name" use $VAR but failed when "Namespace" also uses $VAR

Steps to Reproduce the Problem

  1. In addition to this plugin, also install plugins:

    • Folder
    • Folder properties
  2. Create a folder.

  3. Configure the following folder properties KUBE_API, KUBE_CLUSTER, KUBE_CONTEXT, KUBE_NS: image

  4. Create a job inside that folder that use the following kubectl configuration. Also ensure "Folder properties" is ticked: image

  5. Add a shell build step using simple kubectl command like kubectl get all.

  6. Job build will error.

  7. Change "Namespace" to use hard-coded value.

  8. Job build will succeed.

Specifications

maxlaverse commented 4 years ago

Hi @MLukman, I have a branch which would add support for environment variable interpolation in the other parameters of the plugin. If you have time and feel adventurous, try out the plugin compiled from the branch. I haven't tested it on a real instance yet but if my tests are not too wrong it should work ™.

I want to give more thoughts about the rollout before going any further. This is potentially a breaking change and I'd like to verify how/if people could have used variable in those fields without interpolation.

MLukman commented 4 years ago

Hi @maxlaverse, I tried the plugin compiled from the branch and it works. Thanks!

Regarding the use of $variable in those fields, I think it is safe to assume that if the '$' symbol is used, it is always meant to denote a variable because it is an invalid character for DNS Label Names, and by inference is invalid for API endpoints, clusters and namespaces. The symbol, however, can be used for a context name, but since the context name field is used to create a temporary context for the job build, you can put disclaimer to the users to only put '$' symbol if they want it to be interpolated as variables.

maxlaverse commented 4 years ago

Released in 1.9.0.