我正在建立一个数据存储,它需要管道中的某些值。
如果我对值进行硬编码,则可以使用invoke azure函数,但是如果我想即时生成或释放值,则无法使用。
我的函数需要一个内部版本号,但是当我尝试在查询参数中添加以下内容时,它将发送单词而不是值:
BuildNumber=$($env:BUILD_BUILDNUMBER)
或
BuildNumber=$env:BUILD_BUILDNUMBER
或 BuildNumber = $(build.BUILDNUMBER)
YAML
variables:
ApplicationCI: 'Test'
steps:
- task: AzureFunction@1
displayName: 'Azure Function: https://site.azurewebsites.net/api/address'
inputs:
function: 'https://site.azurewebsites.net/api/Address'
key: 'MyKey=='
method: GET
queryParameters: 'ApplicationCI=$(ApplicationCI)&BuildNumber=$(build.BUILDNUMBER)&ring=-1&BuildDefinitionName=$(build.DEFINITIONNAME)&BuildOwnerId=$(build.QUEUEDBY)&BuildStartTime=$(system.PIPELINESTARTTIME)&ChangeSet=$(build.SOURCEVERSION)&ReleaseDefinitionName=$(release.DEFINITIONNAME)&ReleaseStart=$(release.DEPLOYMENT_STARTTIME)&SourceLocation=$(build.SOURCEBRANCH)&StagingFolder=$(system.ARTIFACTSDIRECTORY)'
或
variables:
ApplicationCI: 'Test'
steps:
- task: AzureFunction@1
displayName: 'Azure Function: https://site.azurewebsites.net/api/address'
inputs:
function: 'https://site.azurewebsites.net/api/address'
key: 'MyKey=='
method: POST
headers: |
{
"ApplicationCI":"$(ApplicationCI)",
"BuildNumber": "$(build.BUILDNUMBER)",
"ring": "-1",
"BuildDefinitionName": "$(build.DEFINITIONNAME)",
"BuildOwnerId": "$(build.QUEUEDBY)",
"BuildStartTime": "$(system.PIPELINESTARTTIME)",
"ChangeSet": "$(build.SOURCEVERSION)",
"ReleaseDefinitionName": "$(release.DEFINITIONNAME)",
"ReleaseStart": "$(release.DEPLOYMENT_STARTTIME)",
"SourceLocation": "$(build.SOURCEBRANCH)",
"StagingFolder": "$(system.ARTIFACTSDIRECTORY)"
}
有人对我如何将内部版本号的变量值编码到我的调用azure函数调用中有任何建议吗?
更新 改变以使我更加接近
https://site.azurewebsites.net/api/address?code=mykey==&ApplicationCI=Test 1&BuildNumber = 20190508.4&ring = -1&BuildDefinitionName = MyApplication-AzureFunction&BuildOwnerId = $(build.QUEUEDBY)&BuildStartTime = $(system.PIPELINESTARTTIME)&ChangeSet = 23624&ReleaseDefinitionName = MyApplication-AzureFunction&ReleaseStart = $(release.DEPLOYMENT_Location) $ / test / Main&StagingFolder = $(system.ARTIFACTSDIRECTORY)
Apparently I only need values for these
$(build.QUEUEDBY)
$(system.PIPELINESTARTTIME)
$(release.DEPLOYMENT_STARTTIME)
$(system.ARTIFACTSDIRECTORY)
Thanks everyone for your help so far.
答案 0 :(得分:2)
我不确定您使用的是哪个版本,但可行的方法是在程序集中设置内部版本号并阅读。
使用.net核心,您可以在代码中dotnet publish --version-suffix $env:BUILD_BUILDNUMBER
(如果不使用dotnet publish,则可以使用azure管道设置程序集信息任务来完成此操作)
Assembly.GetExecutingAssembly().GetName().Version;
PS。还没有测试过,但是应该可以工作