0
votes

I've tried several articles and threads from Stackoverflow but can't seem to get anywhere. I am trying to take a variable from a .py file which is called in a YAML step and set that variable globally to be used.

In my .py file i have

print(f'##vso[task.setvariable variable=AMLPipelineId;isOutput=true]{pipelineId}')

Then in my YAML pipeline step i have

- task: AzurePowerShell@5
  displayName: 'Run AML Pipeline'
   inputs:
     azureSubscription: '$(azureSubscription)'
     ScriptType: 'InlineScript'
     name: AmlPipeline
     azurePowerShellVersion: 'LatestVersion'
     pwsh: true
     Inline: |
             $username = "$(ARM_CLIENT_ID)"
             $password = "$(ARM_CLIENT_SECRET)"
             $tenantId = "$(ARM_TENANT_ID)"
                  
             python $(Pipeline.Workspace)/AML_Pipeline/build_aml_pipeline.py --wsName $(wsName) --resourceGroup $(ResourceGroupName) --subscriptionId $(subId)

                 
             $MLPipelineId = $AmlPipeline.AMLPipelineId

But it seems like this variable is empty. I know there are other ways of using the "set variable" but this is my latest attempt i.e. something like print('##vso[task.setvariable variable=version;]%s' % (version))

My current approach i followed: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch

1

1 Answers

0
votes
  1. You don't need isOutput=true - that's only needed for referencing variables between different jobs or stages.
  2. "You cannot use the variable in the step that it is defined." - split that script into two steps: one that runs your .py file, second one that uses the newly defined variable.