I have a build pipeline to deploy something to AWS via Azure Devops pipeline using the AWS CodeDeploy task. I want to report on the detail of this deployment by using the output variable of deployment Id from the AWS CodeDeploy task step as an input to query the deployment via the next task AWS CLI command.
Here is the AWS CodeDeploy step, and the configuration of the output variable.
Here is the subsequent step, using that variable.
Here is the output error from the build pipeline.
Code Deploy task:
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 task:
[command]C:\windows\system32\cmd.exe /D /S /C "C:\hostedtoolcache\windows\Python\3.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\3.6.8\x64\Scripts\aws.cmd' failed with exit code 255
It appears to not be converting the variable to actual value. Can anyone assist?
I tested outputting the variable via PowerShell and got this error:
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\_temp\4985f146-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
Using script:
# Write your PowerShell commands here.
Write-Host "variable check"
Write-Host $(codedeploy.deployment_id)
Solved this. The issue was my syntax. I assumed you needed to reference a variable using the reference name.variable $(reference.variable) when in fact you only need to use $(variable). The reference name - while required to specify in the task definition - is not used when referencing the value elsewhere. I was following the Microsoft documentation which states the following:
Use outputs in the same job
In the Output variables section, give the producing task a reference name. Then, in a downstream step, you can use the form $(ReferenceName.VariableName) to refer to output variables.