Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to read or save in a variable the data returned by an Azure Pipelines script?

I have an Azure Devops Pipeline that has a task script like that:

steps:
  - script: python settings.py

This script "returns" (internally makes a print('...')) a value I'd like to save during the pipeline for later use, but I can't find a way to do it.

I've tried logging, but I don't think it's possible:

steps:
  - script: echo '##vso[task.setvariable variable=version]'${python settings.py}

Is it possible in any way or is there none to be able to do this?

Thanks.

like image 538
Toni Miguel López Avatar asked Sep 19 '19 09:09

Toni Miguel López


People also ask

How are output variables used in release pipeline?

Just specify the reference name in the blank of task, and then, you can call this output variable abc by using the format: <reference name>. <variable name> . For example, if you specify the reference name as mycustom , just call the output variable by using $(mycustom. abc) .

How do I export variables from Azure DevOps pipeline?

We could write it out to a json/xml file via power shell task, and publish the file as artifacts. Then read in that file via PowerShell in your release definition. Also, we could pass the variable from build to release via the extension Variable Tools for Azure DevOps Services.

What is output variable in Azure DevOps?

An output variable is a specific kind of pipeline variable that is created by a task. The deployment task assigns a value to a variable which then makes it available to use across a pipeline.


1 Answers

You can add this code in the python script to save the value for later use in the pipeline. The idea is output this to the console and VSTS will automatically save it under the variable - version.

print('##vso[task.setvariable variable=version;]%s' % (version))
like image 56
R Jain Avatar answered Nov 11 '22 17:11

R Jain