VSTS发布管道-令牌替换 [英] VSTS Release pipeline - token substitution

查看:66
本文介绍了VSTS发布管道-令牌替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用替换令牌(来自 VS Marketplace )和到目前为止,对于web.config文件中的动态连接字符串替换,它一直为我提供了很好的帮助.在Web.Release.config中,它的工作方式如下:

I've been using Replace Tokens (from VS Marketplace) and it served me well so far for the dynamic connection string substitution in the web.config file. The way it works, in the Web.Release.config I have a construction like this:

<connectionStrings>
    <add name="Default"
        connectionString="__AzureDBConnectionString__"
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>

当我在VSTS中开始发布时,它将使用发布管道中的变量值替换此标记(在"__"之间).因此,我总是有一个与相关环境相对应的连接字符串. 昨天,我决定在此文件中添加更多变量,希望它也能正常工作,因为出于安全原因,我有很多应该进行参数设置的键. 好吧,如果我将这样的内容添加到文件中:

When I start release in VSTS, it replaces this token (in between "__") with the variable value in the release pipeline. So, I always have a connection string that corresponds to the relevant environment. Yesterday I decided to add some more variables into this file, hoping it'll work as well, as I have a lot keys that should be parametrized for security reasons. Well, if I add to the file something like this:

<appSettings>
        <add key="mailToken" value="__mailToken__" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
</appSettings>

它不起作用.在部署的web.config中,我看到value =" mailToken ",即它没有被存储在发布管道中的变量代替(对于连接字符串). 经过大约一天的苦难,我发现唯一可以替换的参数是连接字符串(因为这是在构建"Web.SetParameters.xml"文件中自动生成的唯一参数集).如某些消息源所示,我尝试播放parameter.xml文件,但未成功.重要的是所有变量都应从发布管道变量列表中获取(而不是硬编码在配置文件中). 有人可以建议一种替代appSetting或其他解决方法中的值的正确方法吗(没有替换令牌"任务等)?

it doesn't work. In the web.config which is deployed, I see value="mailToken" i.e. it's not substituted with the variable stored in the release pipeline (as for connection string). After around a day of suffering, I discovered that the only parameter that could be replaced like that is connection string (because this is the only parameter set in auto-generated by the build "Web.SetParameters.xml" file). I tried to play around parameter.xml file as some sources suggest, but no success. It is important that all the variables are taken from the release pipeline variable list (and not hardcoded in config files). Can someone suggest a proper way to substitute the values in appSetting or another workaround (without Replace Tokens task etc.)?

推荐答案

根据您的描述,您正在使用Web部署程序包(Web.SetParameters.xml),默认情况下,Web.Release.config中的appSettings不会已添加到Web.SetParameters.xml文件中,但是在生成Web部署程序包时将直接替换web.config文件中的值,因此web.config文件(在zip程序包文件中)中的mailToken的值将为 mailToken .

According to your description, you are using Web Deployment Package (Web.SetParameters.xml), by default the appSettings in Web.Release.config won’t be added to Web.SetParameters.xml file, but will replace the value in web.config file directly when generate the Web Deployment package, so the value of mailToken in web.config file (in zip package file) will be mailToken.

因此,替换它的简单方法是在File Transforms&中使用XML变量替换. IIS Web App Deploy Azure App Service Deploy 任务的变量替换选项"部分.您只需要在发布定义中添加具有相同名称的键值(mailToken)变量,并选中 XML变量替换选项. (不需要在Web.Release.config中进行配置)

So, the simple way to replace it is using XML variable substitution in File Transforms & Variable Substitution Options section of IIS Web App Deploy or Azure App Service Deploy task. You just need to add the variable with the same name of key value (mailToken) to the release definition and check the XML variable substitution option. (Do not need to configure it in Web.Release.config)

更多信息,您可以参考: XML变量替换

More information, you can refer to: XML variable substitution

这篇关于VSTS发布管道-令牌替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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