Hello,
I tried searching for similar topics but didn’t find anything related to this specific matter, but maybe I’ve been using the wrong terminology so I’ll try to break it down.
Problem
There’s a recurring pattern in our build files related to string manipulation of environment variables and parameters that apparently cannot be solved “natively” through the CircleCI config file, and it forces us to embed custom scripts into our workflows and jobs declarations.
Example
- We want to create a Kubernetes namespace for each Git branch that we push to our repository
- The natural approach would be to name the Kubernetes namespace after the branch name itself
- Branches are not always named in a way that Kubernetes would accept them as namespace. For instance, a branch named
PROJ-123-some-crazy-featurewould not qualify as a valid namespace name due to thePROJuppercase characters - Transforming the branch name into lowercase-only characters would solve this, but in order to apply such transformation we’d need to embed some scripting into every place where we need the transformation to happen, something like:
workflows:
development:
jobs:
- build
# Some other jobs...
- prepare-infra:
context: dev
kubernetes-namespace: $(echo "${CIRCLE_PROJECT_REPONAME}-${CIRCLE_BRANCH}" | awk '{print tolower($0)}')
- deploy-chart:
context: dev
kubernetes-namespace: $(echo "${CIRCLE_PROJECT_REPONAME}-${CIRCLE_BRANCH}" | awk '{print tolower($0)}')
requires:
- prepare-infra
In particular, I was expecting something like this (notice the var parameter in the terraform/apply step):
jobs:
- prepare-infra:
parameters:
kubernetes-namespace:
type: string
steps:
- terraform/apply:
var: 'namespace_name=<< parameters.kubernetes-namespace | tolower >>'
workflows:
development:
jobs:
- build
# Some other jobs...
- prepare-infra:
context: dev
kubernetes-namespace: '${CIRCLE_PROJECT_REPONAME}-${CIRCLE_BRANCH}'
- deploy-chart:
context: dev
kubernetes-namespace: '${CIRCLE_PROJECT_REPONAME}-${CIRCLE_BRANCH}'
requires:
- prepare-infra
I guess it would be something similar to what Jinja offers as “filters”.
Questions
- Is this possible?
- Are there built-in functions in the lines of
tolowerthat we can use to avoid embedding custom scripts? - Moreover, is there for us to define custom functions/filters?