renevanosnabrugge / SendEmail-BuildTask

MIT License
17 stars 20 forks source link

Using variables/variablegroups from devops library in body #44

Open rasmusskov opened 2 years ago

rasmusskov commented 2 years ago

I have defined some Variable Groups in my devops project, and is updating the values in there when pre-deploying my repository. When doing the actual release, i would like to compose an email, where the body contains some of the values of the variables.

Something like

Release completed for the sandbox. Releaseno is $LibraryName$VariableName

Is this possible, and can someone help with the syntax?

Gudui commented 1 year ago

@rasmusskov did you ever try? Did it work?

rasmusskov commented 1 year ago

@Gudui Didnt really get an aswer in here, so kept investigating.

I am using the devops api for this... Sample code something like below

 if ($null -eq $ENV:SYSTEM_ACCESSTOKEN)
    {
        Write-Error "No access token provided. Enable 'Allow scripts to access the OAuth token' in Deployment Group Job"
    }

    $URL = "$($ENV:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$($ENV:SYSTEM_TEAMPROJECTID)/_apis/distributedtask/variablegroups"

    $variablegroups = Invoke-RestMethod -Uri $url -Headers @{
        Authorization = "Bearer $ENV:SYSTEM_ACCESSTOKEN" # Provided by ADO thanks to OAuth checkbox
    }