I am trying to set up bitbucket pipelines and one thing I want to do is be able to create variables from values of other variables.
I've tried several different ways of specifying syntax, and the repo level variable renders whatever the value is at a literal string and doesn't seem support variable expansion. The documentation doesn't mention this at all.
As an example, I am setting up account level variables for the default ports our microservices are running on. This allows us to centralize where we define these and reference from so values aren't duplicated across different repos.
So, at the account level, I have values like:
SERVICE_1_PORT=8080
SERVICE_2_PORT=8081
SERVICE_3_PORT=8082
I'd like to have a generic template for a bitbucket pipelines file that can be reused across different repos so, for instance, in the SERVICE_1 repo, I can have a repo variable like:
THIS_SERVICE_PORT=$SERVICE_1_PORT
and then, for SERVICE_2, the repo level variable would become
THIS_SERVICE_PORT=$SERVICE_2_PORT
That way, they both could use the same pipelines template that simply declares something like
- export SERVICE_PORT=$THIS_SERVICE_PORT
Instead of having two *very similar, yet different* pipeline files that only differ in that one has
- export SERVICE_PORT=$SERVICE_1_PORT
and the other has
- export SERVICE_PORT=$SERVICE_2_PORT
and so on...
Another thing I've done in the past with other CI/CD systems is have a variable defined as something like:
CREDENTIAL_STRING=${username}:${password}@${server}
where the ${username}, ${password} , and ${server} values can be scoped per environment or project groups, or resources, or whatever.