How to pass parameters to pipeline during trigger run in Azure Data Factory? - azure

As far as I know I can pass a parameters in manual run(trigger now). But how if I want to set the pipeline to autorun everyday, and be able to pass a parameter without entering the trigger now pipeline page?
Another question is that during the deign of my pipeline, I have set up few parameters and logic linked to it, like "if the parameter is null then run all table, it there is value, then only run that table", that is for user enter re-run for specific table.
However, I noticed that the message "Parameters that are not provided a value will not be included in the trigger.", does that mean my logic in the pipeline cannot be setup this way if I want to trigger it automatically everyday?
Thanks a lot!

Implementing heavy ADF logic can be difficult. You can set the default value for parameters but I assume those need to be set dynamically?
You could also use pipeline variables and an Activity at the beginning of your pipeline named "Set variable" and work with that using expressions to run your activity based on variables that are set with parameters?
In our project we did even something more complicated and we deploy and trigger a Pipeline once a week from Azure Devops. So not the ADF itself triggers the pipeline but AzureDevops scheduled run does.
Powershell:
$parameters = #{
"parameterName1" = $parameterValue
"parameterName2" = $ParameterValue
}
Invoke-AzDataFactoryV2Pipeline -DataFactoryName $DataFactoryName -ResourceGroupName
$ResourceGroupName -PipelineName $pipelineName -Parameter $parameters
With powershell you can implement any logic you really want at this point passing values to ADF.

Related

Unable to use output variables from a PowerShell script in the Override Parameters of a Resource Group deployment task in Azure DevOPS

I have a PowerShell script where I have multiple output variables generated with the following syntax :
Write-Host ("##vso[task.setvariable variable=appObjectId;issecret=false]"+$appObjectId)
In the PowerShell task in Azure DevOPS, I have set the Output variables as follow:
Then, I use my output variables in an Azure Resource Group deployment as follow:
Unfortunately, when I look into the deployment details in Azure, I can see that the parameters of my ARM are not filled out with the value of the output parameters but with the name of it:
Important information: the ARM deployment task is done inside a task group. My PowerShell script is in the pipeline, just before the call to the Task Group. I tried to put the script inside the Task Group but I have the exact same issue.
I found the root cause: I need to enclose the parameter "$(myParam)" in the tasks where I need to use it. Otherwise, it is not computed.
I think you might have gotten the format wrong for defining the output variable from your Powershell script, this should work -
Write-Host "##vso[task.setvariable variable=appObjectId;isOutput=true]$appObjectId"
Update
Also add is isoutput=true, the defaults to false.
Cause you are not set the variable to appObjectId correctly. There is not AADApplication.appClientid. Then Azure DevOps treat this to string. That's why the parameters of my ARM are not filled out with the value of the output parameters but with the name of it.
No need to use () to include the follow set variable command.
SetVariable: Initialize or modify the value of a variable
##vso[task.setvariable]value
You should use the following syntax :
Write-Host "##vso[task.setvariable variable=appClientID;issecret=false;isoutput=true]value"
More details please refer our official doc here.

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.

Azure Data Factory V1

Is it possible to trigger a pipeline in ADF v1 using Powershell script?
I found this command "Resume-AzureRmDataFactoryPipeline" to trigger the pipeline, but it does not really start the pipeline..
Please advise.
It really depends on what your pipeline does, but an alternative method is setting the status of a slice to waiting, with the following powershell cmdlet:
$StartDateTime = (Get-Date).AddDays(-7)
$ResourceGroupName = "YourRGName"
$DSName = "YourDatasetName"
$DataFactoryV1Name = "YourDFv1Name"
Set-AzureRmDataFactorySliceStatus -DataFactoryName $DataFactoryV1Name -DatasetName $DSName -ResourceGroupName $ResourceGroupName -StartDateTime $StartDateTime -Status Waiting
Replace with your values and run after being logged in and selecting a subscription. What this does is sets some slices to Waiting, and if their startdatetime is in the past, data factory will run them immediately.
Hope this helped!
Resume-AzureRmDataFactoryPipeline will work only on those pipelines which are suspended as this only
resumes a suspended pipeline in Data Factory. Link.
Now, if you want to start a pipeline then start with -
New-AzureRmDataFactoryPipeline which would create a pipeline for you and if the pipeline already exists then it would ask for confirmation to replace the existing one.
Once successfully done then you can use Set-AzureRmDataFactoryPipelineActivePeriod to configure active period for the data slices. So, this basically means after you create the pipeline, you specify the period in which data processing occurs by specifying the active period for the pipeline in which the data slices are processed. These cmdlets would run only when the data factory is already created.
You could also choose to run Set-AzureRmDataFactoryPipelineActivePeriod independently to define the active periods of the pipeline and run your data factory.
You can use this command Set-AzureRmDataFactorySliceStatus. Through this, you can reset the slice to "Pending Execution" state. You also get the option to set the same status for Upstream slices so that the entire pipeline can re-run.
See this for reference https://learn.microsoft.com/en-us/powershell/module/azurerm.datafactories/set-azurermdatafactoryslicestatus?view=azurermps-5.4.0

Azure Team Services CI - Release Variable does not work

I am trying to automate resource group creation with team services release.
I added azure resource group project to the solution and defined administratorLoginPassword variable as a secure string in json definition:
Also I defined administratorLoginPassword variable at the environment level in release definition as the following:
But when I run release it fails with the following reason:
Cannot process command because of one or more missing mandatory
parameters: administratorLoginPassword.
You need to pass that variable explicitly to the template script specifying its value in the Override Template Parameters text box, as follow:
-administratorLoginPassword (ConvertTo-SecureString -String '$(administratorLoginPassword)' -AsPlainText -Force)
Anyway I would suggest to create a proper azuredeploy.parameters.json file where you store all the actual values for all the required template parameters, and pass this file to Template Parameters input of the Azure Resource Group Deployment task. This file could be manipulated during build/release by replacing the content with the values you need, avoiding entirely to play with special parameters of the build task.
The variables created in the Build/Release Definition are disregarded by the Azure Res. Group Deployment task unless you pass it over explicitly as shown above.

trigger azure data factory pipeline

Is there any way to manually trigger a azure data factory pipeline? I would like to have this feature for a demo.
I know that we can suspend and resume a pipeline using power shell scripts.
Thanks.
Here is what I would do.
create everything without pipeline active periods
When you want to run the demo update active periods to dates in the past
If you want to run again, update to another date in the past
Updating dates via powershell would look something like this
Set-AzureDataFactoryPipelineActivePeriod -DataFactoryName $DataFactoryName -PipelineName $PipelineName -StartDateTime $DateInPast -EndDateTime $DateOneDayLessInPast -ResourceGroupName $ResourceGroupName -Force
try following url via postman:
https://management.azure.com/subscriptions/{subId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelines/{pipelineName}/createRun?api-version=2018-06-01
replace {} with your values
remember to add OAuth token. :)

Resources