How to pass variable to Azure DevOps Run Pipeline - azure

I am trying to put predefined value RELEASE_RELEASENAME to Azure DevOps Run Pipeline task, but it ends always with error: "##[error]Build parameters is not a valid json object array. Example valid object: [{"VAR1":"VALUE1","VAR2":"VALUE2"},{"VAR1":"VALUE1","VAR2":"VALUE2"}]"
Azure Setup

You could try the change the expression of the variable like:
[{"var1": "$(Release.ReleaseName)"}]

Related

Pass pipeline variable to release variable Azure DevOps

Created CICD pipeline with trigger release, and Pipeline variable set in to Azure Devops Rest API. Getting variable in pipeline and set Output true using PowerShell.
Write-Host $(webAppName)
echo "##vso[task.setvariable variable=webAppName;isoutput=true]$webAppName"
And set the release pipeline variable using
WebAppName= ${{variables.webAppName}} on the variable tab. It's not working, don't have idea how can we retrive the pipeline variable in release.
The is no official way to pass variables from Build to Release.
Using Variable Groups in Azure Pipeline Library is a good option: https://learn.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=azure-devops&tabs=yaml
Another work around, you could store the variable values in a file and attach that as a Build Artifact. That way you can read the file in the release pipeline by downloading Build Artifacts and set the variable again. You could check my answer here: is there any way to pass variables from CI to CD pipeline

Use secret variable sent via REST API

I currently have an Azure devops pipeline that I trigger with a call to the REST API. I use the "Run pipeline" interface: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-6.1
With this API I can trigger a run of my AZDO pipeline, and I can send variables that are NOT secrets. I can then access these parameters as env variables in the AZDO pipeline.
The format of these variables is defined here: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-6.1#variable. Please note the isSecret part.
However, I soon as I set isSecret to true, I'm unable to read these variables as env variables on the pipeline side. They just appear like they don't contain anything.
I know I could use the library and a variable group to pass secret to the pipeline, but this isn't what I'm trying to do. I'd like to know if I can pass secret to the pipeline via the REST API.
I've been looking around for a few hours and I haven't found anything.
When setting IsSecret to true in API body, the echo output in pipeline will be shown as ***
"variables": {"variable 1": { "value": "{Some Vaule}", "isSecret" : true}
If you want to read these variables on pipeline side, you could put your variable into a .txt file and publish the .txt file to Artifacts to check.
If you want to use this API passed secret value as environment variable in your pipeline, you should define it as environment variable first instead of using it directly: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#secret-variables

How can I create a variable group, update the value in a pipeline, and query the value?

As an end goal I am trying to create an Azure DevOps Dashboard widget that has a table with the project name, the environments (dev, test, prod), and the current version of that project.
I was thinking about creating a variable group in a project called version, with variables such as: dev = 0.0.0, test = 0.0.0, prod = 0.0.0
Then I would need to called these variables within my pipeline to update the value, i.e. dev = 0.0.1.
After the variable gets updated, I want to query my variable group and display the results in the Query Results extension.
Is this even possible or is there a better way to do this?
How can I create a variable group, update the value in a pipeline, and query the value?
You could use the REST API or CLI command to achieve this:
For CLI, you could use the command:
az pipelines variable-group variable create
az pipelines variable-group variable update
az pipelines variable-group variable list
You could refer this document for some more details.
Besides, you could also use the REST API:
POST https://dev.azure.com/{organization}/{project}/_apis/distributedtask/variablegroups?api-version=5.1-preview.1
The REST API document here.

Release Azure Functions and file transformations

I have a lot of Azure Functions projects to deploy on Azure. I set build and pipeline for them. For example, this is one Release for an Azure Function.
Under Variables I defined all variables for the environments (one for dev, one for stage and one for production).
There is only one step for deploying the Azure Functions on Azure. I want to add/replace in the local.settings.json the right settings for an environment. I'm not be able to find how to configure that.
In other project, if I use Azure App Service Deploy, there is a section File Transforms & Variable Substitution Options.
How can I do the same in the release of an Azure Functions? What is the correct strategy or best practice?
Update and Solution
I thought it was much straightforward. I think this is the solution. In the App settings under Application and Configuration Settings, I have to specified each variable and its value using the ... in that line.
I can type or copy in this field. The syntax is
-variableName "$(variablename)"
I'm using quotes because if in the value there is any space (for example in the connection string you have Initial Catalog) DevOps raises an error. For array, I'm still using :.
Another way is to use File Transform task to substitute the variables in local.settings.json file with pipeline variables. See here for more information.
With File Transform task, you donot have to specify each variable and its value in App settings of deploy Azure Functions task.
You can add a File Transform task before the deploy Azure Functions task. Then define the variables(eg. KeyVaultSettings.ClientId) in your pipeline variables.
Then set the Package or folder, file format and Target files in File Transform task. See below:
This is what I've done in my Azure Functions pipeline (it's yaml, but you'll get the idea).
Create one stage per environment in your pipeline
Create your pipelines variables and asign a different value based on scope (stage)
Create a configuration entry (see picture) in your pipeline and asign the variable value.
Consume the configuration entry in your Azure Function (in my case I use Environmental Variables for that)
Use pipeline environment in your azure function configuration

Pass a value from inside the Azure ADF pipeline to a PowerShell where the pipeline invoked

I want to do some steps in my PowerShell based on a value from an Azure ADF(Azure Data Factory) pipeline. How can I pass a value from an ADF pipeline to the PowerShell, where I invoked this ADF Pipeline? So that, I can do the appropriate steps in the PowerShell based on a value I received from ADF pipeline.
NOTE: I am not looking for the run-status of the pipeline (success, failure etc), but I am looking for some variable-value that we get inside a pipeline - say, a flag-value we obtained from a table using a Lookup activity etc.
Any thoughts?
KPK, the requirements you're talking about definitely can be fulfilled though I do not know where does your Powershell scripts run.
You could write your Powershell scripts in HTTP Trigger Azure Function,please refer to this doc. Then you could get the output of the pipeline in Powershell:
https://learn.microsoft.com/en-us/powershell/module/azurerm.datafactoryv2/invoke-azurermdatafactoryv2pipeline?view=azurermps-4.4.1#outputs.
Then pass the value you want to HTTP Trigger Azure Function as parameters.

Resources