0
votes

I am wanting opinion on the following. Have a javascript qna bot that I have in Azure DevOps. I have an azure pipeline created that deploys to an Azure environment. This works well. However, this is a common use bot that can be used in multiple scenarios. Write Once, Use Many. So I want to variabl-ize the process for multiple environments (DEV vs PROD) and instances (PROD1, PROD2, PROD3...)

1st Case: Within the project, there is a .env file with name-value pairs stored. I need to have distinct values for multiple environments and instances. One option could be to have a distinct file per environment+instance. So

.env.DEV, .env.PROD1, .env.PROD2, .env.PROD3, etc.

And then as part of the build process that zips the files, rename only one of the .env files by dropping the suffix based on the case. Can delete the other .env files prior to zipping. Is this a good way to do it OR is there a more standardized process that I should use?

2nd Case: As part of the deployment, I want to variabl-ize the azure-pipeline.yml file so that the target webapp, resource group, subscription, etc are dynamic (different for DEV, PROD1, PROD2, ...). I can create multiple yaml files and link it to separate pipelines. Is this the way? Or am I creating one pipeline and somehow toggling these values for 'n' different cases?

I can hack something. But I wanted to make sure I was using the right approach before starting.

Thanks in advance, Jake.

1

1 Answers

2
votes

1st Case:

Is this a good way to do it OR is there a more standardized process that I should use?

I suggest you can use replace token task to achieve your needs which could be more convenient. Here is my sample:

1.*.env file:

name1:#{value1}#
name2:#{value2}#
name3:#{value3}#

2.Create variables and set values when running the pipeline:

enter image description here

3.Replace token task:

- task: replacetokens@3
  inputs:
    targetFiles: '**/*.env'
    encoding: 'auto'
    writeBOM: true
    actionOnMissing: 'warn'
    keepToken: true
    tokenPrefix: '#{'
    tokenSuffix: '}#'
    useLegacyPattern: false
    enableTelemetry: false

4.Result of *.env file:

name1:a
name2:b
name3:c

2nd Case:

I can create multiple yaml files and link it to separate pipelines. Is this the way? Or am I creating one pipeline and somehow toggling these values for 'n' different cases?

I suggest you can use parameters and select values when running pipelines. For example:

parameters:
  - name: subscription
    type: string
    default: test1
    values:
      - test1
      - test2
  - name: WebAppName
    type: string
    default: test1
    values:
      - test1
      - test2
  - name: ResourceGroupName
    type: string
    default: test1
    values:
      - test1
      - test2

steps:

- task: AzureAppServiceManage@0
  inputs:
    azureSubscription: ${{ parameters.subscription }}
    Action: 'Stop Azure App Service'
    WebAppName: ${{ parameters.WebAppName }}
    SpecifySlotOrASE: true
    ResourceGroupName: ${{ parameters.ResourceGroupName }}

You can choose the resource group name and subscription name when running pipelins: enter image description here