I am using the below code to retrieve the build id of the latest successful build from the azure pipeline . But throws the below error .Please help in fixing the issue
code :
- task: PowerShell@2
inputs:
targetType: 'inline'
script:
$organization = "org_name"
$project = "project_name"
$definitionid = "27"
$pat = "eq7pqxcycdp6crbrygwh73ua2kzdvsett3p2sjcx5j"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "", $pat)))
$baseUrl = "https://dev.azure.com/$organization/$project/_apis/build/latest/$definitionid?api-version=5.1-preview.1"
$latestbuild = Invoke-RestMethod -Uri $baseUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET
Write-Host $latestbuild.id
$id1 = $latestbuild.id
Write-Host "##vso[task.setvariable variable=buildid]$id1"
Error :
##[error]Unable to locate executable file: 'pwsh'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.
You need to install Powershell Core on your machine that hosts Azure DevOps agent. This adds pwsh
to the PATH
, which will fix your build. Powershell Core Installation guide for Linux.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With