This is my first post here so I am sorry if I miss any info. I will do my best to explain my challenge.
I have 2 PS scripts and having trouble of reading variable (var1 and var2) values on pipeline side.
Below is how I tried it but want able to manage it to work.
1st one that is runed on jump server and it is successfully triggering pipeline:
# Set variables for the Azure DevOps organization and project
$orgName = "your-organization-name"
$projectName = "your-project-name"
# Set the URL for the Azure DevOps REST API
$baseUrl = "https://dev.azure.com/$orgName/$projectName/_apis"
# Set variables for the pipeline definition ID, build definition ID, and pipeline variables
$pipelineId = "your-pipeline-id"
$buildDefinitionId = "your-build-definition-id"
$pipelineVariables = @{
HELLO_WORLD = "hello_value"
var1 = "value1"
var2 = "value2"
}
# Convert the pipeline variables to JSON
$jsonVariables = $pipelineVariables | ConvertTo-Json
# Set the URL for the pipeline trigger REST API
$triggerUrl = "$baseUrl/pipelines/$pipelineId/runs?api-version=6.1-preview"
# Create the body of the request
$body = @{
definition = @{
id = $buildDefinitionId
}
variables = $jsonVariables
} | ConvertTo-Json
# Invoke the REST API to trigger the pipeline and save the response to a variable
$response = Invoke-RestMethod -Uri $triggerUrl -Method Post -Body $body -ContentType "application/json"
# Get the full content of the response
$responseContent = $response | ConvertTo-Json -Depth 100
# Print the response content to the console
Write-Host "Response content: $responseContent"
2nd one is PowerShell task where I enter image description here try to read data in pipeline without success:
# Read the pipeline variables from the environment
$hello = $env:HELLO_WORLD
$var1 = $env:var1
$var2 = $env:var2
# Output the variables to the console
Write-Host "hello = $hello"
Write-Host "var1 = $var1"
Write-Host "var2 = $var2"
I have also tried to add them to Environment Variables enter image description here
result: enter image description here Any help would be appreciated.