Azure DevOps 使用来自 AWS CodeDeploy 的部署 ID 的输出变量作为管道中下一个任务的输入,而不是将变量转换为实际值
Azure DevOps using output variable of deployment id from AWS CodeDeploy as input to next task in pipeline, not converting variable to actual value
我有一个构建管道,可以使用 AWS CodeDeploy 任务通过 Azure Devops 管道将某些内容部署到 AWS。我想通过使用来自 AWS CodeDeploy 任务步骤的部署 Id 的输出变量作为输入来报告此部署的详细信息,以通过下一个任务 AWS CLI 命令查询部署。
这里是AWS CodeDeploy步骤,以及输出变量的配置。
这是使用该变量的后续步骤。
这是构建管道的输出错误。
代码部署任务:
Started deployment of new revision to deployment group VSTSEc2Targets for application VSTSTestApp, deployment ID d-PN4UXHVJO
Setting output variable deployment_id with the ID of the deployment
Waiting for deployment to complete
AWS CLI 任务:
[command]C:\windows\system32\cmd.exe /D /S /C "C:\hostedtoolcache\windows\Python.6.8\x64\Scripts\aws.cmd deploy get-deployment --deployment-id "$(codedeploy.deployment_id)""
An error occurred (InvalidDeploymentIdException) when calling the GetDeployment operation: Specified DeploymentId is not in the valid format: $(codedeploy.deployment_id)
##[error]Error: The process 'C:\hostedtoolcache\windows\Python.6.8\x64\Scripts\aws.cmd' failed with exit code 255
似乎没有将变量转换为实际值。有人可以帮忙吗?
我测试了通过 PowerShell 输出变量并收到此错误:
variable check
codedeploy.deployment_id : The term 'codedeploy.deployment_id' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At D:\a\_temp85f146-ca74-46a3-aed2-aa67cdc2e01a.ps1:5 char:14
+ Write-Host $(codedeploy.deployment_id)
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (codedeploy.deployment_id:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException
##[error]PowerShell exited with code '1'.
##[section]Finishing: PowerShell Script
使用脚本:
# Write your PowerShell commands here.
Write-Host "variable check"
Write-Host $(codedeploy.deployment_id)
解决了这个问题。问题是我的语法。我假设您需要使用引用 name.variable $(reference.variable) 来引用变量,而实际上您只需要使用 $(variable)。引用名称 - 虽然需要在任务定义中指定 - 在别处引用值时不使用。我正在关注 Microsoft 文档,其中说明如下:
在同一作业中使用输出
在输出变量部分,为生产任务指定一个参考名称。然后,在下游步骤中,您可以使用 $(ReferenceName.VariableName) 形式来引用输出变量。
我有一个构建管道,可以使用 AWS CodeDeploy 任务通过 Azure Devops 管道将某些内容部署到 AWS。我想通过使用来自 AWS CodeDeploy 任务步骤的部署 Id 的输出变量作为输入来报告此部署的详细信息,以通过下一个任务 AWS CLI 命令查询部署。
这里是AWS CodeDeploy步骤,以及输出变量的配置。
这是使用该变量的后续步骤。
这是构建管道的输出错误。
代码部署任务:
Started deployment of new revision to deployment group VSTSEc2Targets for application VSTSTestApp, deployment ID d-PN4UXHVJO
Setting output variable deployment_id with the ID of the deployment
Waiting for deployment to complete
AWS CLI 任务:
[command]C:\windows\system32\cmd.exe /D /S /C "C:\hostedtoolcache\windows\Python.6.8\x64\Scripts\aws.cmd deploy get-deployment --deployment-id "$(codedeploy.deployment_id)""
An error occurred (InvalidDeploymentIdException) when calling the GetDeployment operation: Specified DeploymentId is not in the valid format: $(codedeploy.deployment_id)
##[error]Error: The process 'C:\hostedtoolcache\windows\Python.6.8\x64\Scripts\aws.cmd' failed with exit code 255
似乎没有将变量转换为实际值。有人可以帮忙吗?
我测试了通过 PowerShell 输出变量并收到此错误:
variable check
codedeploy.deployment_id : The term 'codedeploy.deployment_id' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At D:\a\_temp85f146-ca74-46a3-aed2-aa67cdc2e01a.ps1:5 char:14
+ Write-Host $(codedeploy.deployment_id)
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (codedeploy.deployment_id:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException
##[error]PowerShell exited with code '1'.
##[section]Finishing: PowerShell Script
使用脚本:
# Write your PowerShell commands here.
Write-Host "variable check"
Write-Host $(codedeploy.deployment_id)
解决了这个问题。问题是我的语法。我假设您需要使用引用 name.variable $(reference.variable) 来引用变量,而实际上您只需要使用 $(variable)。引用名称 - 虽然需要在任务定义中指定 - 在别处引用值时不使用。我正在关注 Microsoft 文档,其中说明如下:
在同一作业中使用输出
在输出变量部分,为生产任务指定一个参考名称。然后,在下游步骤中,您可以使用 $(ReferenceName.VariableName) 形式来引用输出变量。