Open pflugs30 opened 2 years ago
I have the same problem using "ECRPushImage@1", it seems to expose the variable using isOutput=false;
which doesn't allow the variable to be propagated in future jobs.
Here the DevOps doc about this: Set a multi-job output variable
example:
trigger:
- main
pool:
vmImage: ubuntu-latest
jobs:
- job: Build
steps:
- task: ECRPushImage@1
name: EcrPushImage
displayName: 'Push to AWS ECR'
inputs:
awsCredentials: 'AWS-Prod'
regionName: 'us-east-1'
imageSource: 'imagename'
sourceImageName: 'myImageRepository'
repositoryName: 'myImageRepository'
pushTag: '$(Build.BuildId)'
outputVariable: 'imageName'
- script: echo $(imageName) # output the full image name with tag
- job: Deploy
dependsOn: Build
variables:
imageName: $[ dependencies.Build.outputs['EcrPushImage.imageName'] ]
steps:
- script: echo $(imageName) # output an empty string
The EcrPushImage
task will print the following in the console:
##vso[task.setvariable variable=imageName;isOutput=false;issecret=false;]ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/myImageRepository:x
Note the isOutput=false
which prevents the variable from being propagated to future jobs.
Summary
When reading the documentation regarding output variables (such as the Elastic Beanstalk Create App Version task), I got the impression the variable would be available as other output variables, such as in this example from the Azure documentation. That documentation shows this example:
In this example, the output variable from stage
One
, taskProduceVar
is available to the second stage through thestageDependencies
object. I assumed the AWS Toolkit output variables would behave this way, too, given their names as "output variables".When I ran some tests, however, I found the values passed to the task's output variable was not available to other stages. Here's a simple pipeline I ran to exercise this task:
Notice in the
OutputTest
task, theversionlabel
variable outputs an empty string. I wanted to understand why. Upon a closer inspection of theBeanstalkCreateApplicationVersion/TaskOperations
code (see this line), I found a call to theazure-pipelines-task-lib/task.js: setVariable
function. In all usages of this function in the AWS Toolkit project, theisOutput
parameter is not passed, and so it is set tofalse
by default. Thus, the task "output variable" is only exposed to the job and is not available to dependent stages.Suggestions
I see two possible paths forward:
setVariable
to passisOutput = true
so the variable will be available as an output to dependentWorkaround
Here's a possible workaround to expose the variable to other stages:
In the above example, the
setOutputs
step loads the local task variable into a stage output variable so it can be referenced in the next stage.