Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting release and build numbers from Azure DevOps Release Pipeline to display in website

I would like to be able to display the release number (*1 in pic) and the build number (*2 in pic) in Asp.Net MVC Core website - FOR that specific website, which was built and released with Azure DevOps.

So if I check code in for an MVC website, the build and release process kicks in and deploys the website - and now I want the same website to display "Release xxxxx" in the footer.

It could be in a JSON file, an environment variable or something - as long as I can access it from Asp.Net Core, I am happy.

How can that be achieved?

like image 546
Kjensen Avatar asked Sep 07 '25 09:09

Kjensen


1 Answers

If you want in the current app that you built and deployed to display the data you can get the values of the variables like each environment variable:

var releaseName = Environment.GetEnvironmentVariable("Release_ReleaseName", EnvironmentVariableTarget.Process);
var buildNumber= Environment.GetEnvironmentVariable("Build_BuildNumber", EnvironmentVariableTarget.Process);

If you want to display the data in an external app:

You can get all the release data with Azure DevOps Rest API. the API for release is Releases - Get Release:

GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}?api-version=5.1

You got a big JSON with the release info, including the release name:

{
    "id":  205,
    "name":  "Release-93",

And in the artifact array, you can get the build id (under definitionReference.version.name):

"version":  {
              "id":  "1439",
              "name":  "TestVars_20190829.1439..11"

So in your Asp.Net MVC Core app just make a GET rest API call and you have all the data.

In addition, you can use the .NET client libraries for Azure DevOps Services and get the data with GetRelease() method:

string projectName = "TestProject";
VssConnection connection = Context.Connection;
ReleaseHttpClient releaseClient = connection.GetClient<ReleaseHttpClient>();

List<WebApiRelease> releases = releaseClient.GetReleasesAsync(project: projectName).Result;

int releaseId = releases.FirstOrDefault().Id;

// Show a release
WebApiRelease release = releaseClient.GetReleaseAsync(project: projectName, releaseId: releaseId).Result;
// Now get the release name and build nubmer
like image 85
Shayki Abramczyk Avatar answered Sep 11 '25 01:09

Shayki Abramczyk