Azure pipeline dynamic creation of variables based on parameters

0 votes

I've included an azure-pipeline.yml file that references templates for auditing, testing, building, and deployment.

What I need to work on is piping Azure DevOps Library values/secrets. The catch is that each search refers to different strings/secrets.

E.g. The node.js services have this service A has a cache connection string as process.env.CACHE_CONNECT service B has a cache connection string as process.env.CACHE_CONNECTION_STRING service C has a cache connection string as process.env.CONNECT_TO_CACHE

I intend to pass in a parameter list and then map over it to create variables that can be used in multiple places and also passed into the docker build/deploy steps.

The issue is creating variable key/value pairs dynamically.

Is this a possibility? Is there a better way to approach this?

name: CD

parameters:
- name: environment
  type: object
  default:
  - foo
  - bar
- name: dotEnvPairs
  type: object
  default:
  - envKey: 'NODE_ENV'
    libraryKey: Production
  - envKey: 'CACHE_STRING'
    libraryKey: 'testMe'

variables:
- group: WebDevelopment   

trigger:
- main

pool:
  vmImage: ubuntu-latest

steps:

- ${{ each value in parameters.dotEnvPairs }}:

# The goal is to do something like this:
# <value.envKey> = <variableGroup<value.libraryKey>
  - script: |
      echo Env name is ${{ value.envKey }}
      echo Env value is ${{ value.libraryKey }}
      echo Static key $(testMe)
      echo Dynamic A key %$(value.libraryKey)%
      echo Dynamic B key %${{value.libraryKey}}%
      echo Dynamic C key %$(variables[value.libraryKey]: value)%

I'm automating service deployment, but I can't touch any of the base code at this time.

Jan 3, 2023 in DevOps on Cloud by Damonlang
• 1,230 points
1,426 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In DevOps on Cloud

0 votes
0 answers
0 votes
1 answer

Advantages of using DevOps with Azure

One of the main advantages is the ...READ MORE

answered Mar 29, 2019 in DevOps on Cloud by Yesha
662 views
+2 votes
0 answers

Codedeploy, email notification based on codedeploy success status/events.

is there a way or python code ...READ MORE

Oct 11, 2019 in DevOps on Cloud by Rishi
• 210 points

closed Oct 11, 2019 by Kalgi 885 views
0 votes
0 answers

dotnet build vs publish on Azure DevOps

I have a console app for .NET Core 2.0.  I can successfully create, distribute, and operate this software locally.  In Azure DevOps, I can successfully create and publish this app.  However, I am unable to launch the finished product if I construct the app in Azure DevOps. I tried creating in Azure DevOps using: dotnet build -c ...READ MORE

Dec 13, 2022 in DevOps on Cloud by Nicholas
• 7,760 points
1,181 views
0 votes
0 answers
0 votes
1 answer
0 votes
0 answers

OWASP Zed Attack Proxy Scan in DevOps pipeline

I want to do the "Authenticated Scan" ...READ MORE

Mar 15, 2022 in DevOps Tools by Kichu
• 19,050 points
828 views
0 votes
1 answer
0 votes
0 answers

Multiple YAML build pipelines in Azure DevOps

Using the new YAML way I want ...READ MORE

Mar 15, 2022 in DevOps Tools by Kichu
• 19,050 points
1,113 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP