InteXX
InteXX

Reputation: 6367

From within a Build/Release pipeline, can we discover its path?

In Azure DevOps, we can organize our Build/Release definitions into high-level folders:

enter image description here

Example: for every pipeline that resides in the Framework folder, I want to conditionally execute a certain task. The pre-defined Build and Release variables provide a plethora of ways to discover information about the underlying file system, but seemingly nothing for this internal path information.

During a pipeline run, is it possible to determine the folder/path that it resides in?

Upvotes: 0

Views: 342

Answers (1)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41565

You can check it with Rest API - Builds - Get:

GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}?api-version=6.0

In the response you get the definition details including the path:

"definition":  {
                   "drafts":  [

                              ],
                   "id":  13,
                   "name":  "TestBuild",
                   "url":  "https://dev.azure.com/xxxxx/7fcdafd5-b891-4fe5-b2fe-xxxxxxx/_apis/build/Definitions/13?revision=1075",
                   "uri":  "vstfs:///Build/Definition/13",
                   "path":  "\\Test Folder",
                   "type":  "build",
                   "queueStatus":  "enabled",
                   "revision":  1075,
                   "project":  {
                                   "id":  "7fcdafd5-b891-4fe5-b2fe-9b9axxxxx",
                                   "name":  "Sample",
                                   "url":  "https://dev.azure.com/xxxx/_apis/projects/7fcdafd5-b891-4fe5-b2fe-9xxxxxx",
                                   "state":  "wellFormed",
                                   "revision":  97,
                                   "visibility":  "private",
                                   "lastUpdateTime":  "2021-03-22T10:25:39.33Z"
                               }
               },

So:

  • Add a simple PS script that invokes the rest API (with the $(Build. BuildId) pre-defined variable)
  • Check the value of the path property
  • If it contains the Framework folder set a new variable with this command:
Write-Host "##vso[task.setvariable variable=isFramework;]true"

Now, in the task add a custom condition:

and(succeeded(), eq(variables['isFramework'], 'true'))

Upvotes: 1

Related Questions