0
votes

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.

enter image description here

Here is the subsequent step, using that variable.

enter image description here

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)
1
If you add a Powershell task after the AWS CodeDeployment step, then print the variable, what's result will you get? - Frank Wang-MSFT
Hi Frank, can you advise what that task would look like? e.g. is it just Write-Output $(variable) - JamesMatson
Yes, you can try to use Write-host $(variablename) or Write-Output $(variable name) to check if the variable has a valid value. - Frank Wang-MSFT
@JamesMatson Did you fixed this issue. Any updates? - Levi Lu-MSFT
The powershell script failed - see my edits in the original question. - JamesMatson

1 Answers

0
votes

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.

From: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=classic%2Cbatch