用于项目和部署特定变量的Azure DevOps管道 [英] Azure DevOps pipelines for project and deployment specific variables

查看:56
本文介绍了用于项目和部署特定变量的Azure DevOps管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望就以下内容发表意见.我在Azure DevOps中有一个javascript qna机器人.我创建了一个Azure管道,该管道可部署到Azure环境.这很好.但是,这是一个可以在多种情况下使用的通用机器人.一次编写,多次使用.因此,我想对多种环境(DEV与PROD)和实例(PROD1,PROD2,PROD3 ...)的过程进行可变化处理

第一种情况:项目中存在一个.env文件,其中存储了名称-值对.我需要为多个环境和实例提供不同的值.一种选择是在每个环境+实例中具有不同的文件.所以

.env.DEV,.env.PROD1,.env.PROD2,.env.PROD3等

然后作为压缩文件的构建过程的一部分,通过删除大小写的后缀来仅重命名其中一个.env文件.可以在压缩之前删除其他.env文件.这是一个好方法吗?还是我应该使用更标准化的流程?

第二种情况:作为部署的一部分,我想可变化azure-pipeline.yml文件,以便目标Web应用程序,资源组,订阅等是动态的(对于DEV不同,PROD1,PROD2,...).我可以创建多个yaml文件并将其链接到单独的管道.是这样吗?还是我要创建一个管道并以某种方式在"n"种不同情况下切换这些值?

我可以破解某些东西.但是我想确保在开始之前使用正确的方法.

预先感谢,杰克.

解决方案

第一种情况:

这是一个好方法吗?还是我应该使用更标准化的流程?

我建议您可以使用

3.替换令牌任务:

 -任务:replacetokens @ 3输入:targetFiles:"**/*.env"编码:自动"writeBOM:是actionOnMissing:警告"keepToken:truetokenPrefix:#{"tokenSuffix:}#"useLegacyPattern:假enableTelemetry:否 

4.*.env文件的结果:

  name1:a名称2:b名称3:c 

第二种情况:

我可以创建多个yaml文件并将其链接到单独的管道.是这样吗?还是我创建一个管道并以某种方式切换这些管道不同情况下的"n"个值?

我建议您可以使用

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.

解决方案

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:

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:

这篇关于用于项目和部署特定变量的Azure DevOps管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆