Я пытаюсь выполнить следующие 2 шага в моем Azure конвейере, запланированном на каждую ночь:
- Поместите самозаверяющий сертификат в хранилище ключей
- Развернуть службу Fabri c кластер через шаблон ARM и использовать отпечаток сертификата и секретный идентификатор в качестве параметров.
Первый шаг создания сертификата в хранилище ключей подходит для меня:
# import the self-signed certificate ccg-self-signed-cert into the Keyvault
- task: AzurePowerShell@5
inputs:
azureSubscription: '${{ parameters.ArmConnection }}'
ScriptType: 'InlineScript'
azurePowerShellVersion: '3.1.0'
Inline: |
$Pwd = ConvertTo-SecureString -String 'MyPassword' -Force -AsPlainText
$Base64 = 'MIIKqQ____3000_CHARS_HERE______1ICAgfQ=='
$Cert = Import-AzKeyVaultCertificate -VaultName $(KeyVaultName) -Name my-self-signed-cert -CertificateString $Base64 -Password $Pwd
echo "##vso[task.setvariable variable=Thumbprint;isOutput=true]$Cert.Thumbprint"
И я думаю, что установил переменную конвейера строкой echo
(не совсем уверен, как это проверить ...)
Но как я могу передать переменную конвейера, содержащую значение отпечатка сертификата, в ARM шаблон в следующей задаче конвейера?
# deploy SF cluster by ARM template and use the SF Cluster certificate thumbsprint as admin cert
- task: AzureResourceManagerTemplateDeployment@3
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: '${{ parameters.ArmConnection }}'
subscriptionId: 'XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX'
action: 'Create Or Update Resource Group'
resourceGroupName: '${{ parameters.resourceGroupName }}'
location: 'West Europe'
templateLocation: 'Linked artifact'
csmFile: '$(Build.SourcesDirectory)/pipelines/templates/sfcluster.json'
csmParametersFile: '$(Build.SourcesDirectory)/pipelines/templates/sfcluster-params.json'
deploymentMode: 'Incremental'
Я использую azure -quickstart-template для создания кластера SF.
И если вы посмотрите на он ожидает отпечаток сертификата в качестве параметра:
"certificateThumbprint": {
"type": "string",
"metadata": {
"description": "Certificate Thumbprint"
}
},
"certificateUrlValue": {
"type": "string",
"metadata": {
"description": "Refers to the location URL in your key vault where the certificate was uploaded, it is should be in the format of https://<name of the vault>.vault.azure.net:443/secrets/<exact location>"
}
},
Как передать значение из AzurePowerShell@5 taks в шаблон ARM, используемый последующей задачей AzureResourceManagerTemplateDeployment@3?
ОБНОВЛЕНИЕ:
Я пробовал следовать Nil ay и поместил 3 переменные в мой sfcluster. json Шаблон ARM:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"clusterName": {
"type": "string",
"defaultValue": "ccg-sfcluster",
"minLength": 5,
"metadata": {
"description": "Name of the SF cluster"
}
},
"certificateThumbprint": {
"type": "string",
"defaultValue": "[$env:THUMBPRINT]",
"metadata": {
"description": "Certificate Thumbprint"
}
},
"sourceVaultResourceId": {
"type": "string",
"defaultValue": "[$env:KEYVAULTID]",
"metadata": {
"description": "Resource Id of the key vault, is should be in the format of /subscriptions/<Sub ID>/resourceGroups/<Resource group name>/providers/Microsoft.KeyVault/vaults/<vault name>"
}
},
"certificateUrlValue": {
"type": "string",
"defaultValue": "[$env:SECRETID]",
"metadata": {
"description": "Refers to the location URL in your key vault where the certificate was uploaded, it is should be in the format of https://<name of the vault>.vault.azure.net:443/secrets/<exact location>"
}
}
},
"variables": {
Однако я получаю синтаксическую ошибку:
2020-05-27T12:31:54.1327314Z There were errors in your deployment. Error code: InvalidTemplate.
2020-05-27T12:31:54.1354742Z ##[error]Deployment template language expression evaluation failed: 'The language expression '$env:THUMBPRINT' is not valid: the string character ':' at position '4' is not expected.'. Please see https://aka.ms/arm-template-expressions for usage details.
2020-05-27T12:31:54.1361090Z ##[debug]Processed: ##vso[task.issue type=error;]Deployment template language expression evaluation failed: 'The language expression '$env:THUMBPRINT' is not valid: the string character ':' at position '4' is not expected.'. Please see https://aka.ms/arm-template-expressions for usage details.
Аналогичная ошибка возникает, если я опускаю квадрат скобки в
"defaultValue": "$env:THUMBPRINT",