@@ -36,34 +36,28 @@ function Test-AzDoServiceConnection {
36
36
[string ]
37
37
$CollectionUri ,
38
38
39
- # PAT to get access to Azure DevOps.
40
- [Parameter ()]
41
- [string ]
42
- $PAT ,
43
-
44
39
# Collection Uri. e.g. https://dev.azure.com/contoso.
45
40
[Parameter (Mandatory , ValueFromPipelineByPropertyName , ValueFromPipeline )]
46
41
[string ]
47
42
$ServiceConnectionName
48
43
)
49
44
50
45
begin {
51
- Write-Verbose " Starting function: Test-AzDoServiceConnection "
52
- $getAzDoProjectSplat = @ {
53
- CollectionUri = $CollectionUri
54
- }
55
- $ProjectId = ( Get-AzDoProject @getAzDoProjectSplat | Where-Object ProjectName -EQ $ProjectName ).Projectid
46
+ $result = @ ()
47
+ Write-Verbose " Starting function: Get-AzDoServiceConnection "
48
+ }
49
+
50
+ process {
56
51
57
52
$getAzDoServiceConnectionSplat = @ {
58
- CollectionUri = $CollectionUri
59
- ProjectName = $ProjectName
53
+ CollectionUri = $CollectionUri
54
+ ProjectName = $ProjectName
55
+ ServiceConnectionName = $ServiceConnectionName
60
56
}
61
57
62
58
$Connections = Get-AzDoServiceConnection @getAzDoServiceConnectionSplat
63
- }
64
59
65
- process {
66
- $connectioninfo = $connections | Where-Object ServiceConnectionName -EQ $ServiceConnectionName
60
+ $connectioninfo = Get-AzDoServiceConnection @getAzDoServiceConnectionSplat
67
61
68
62
$body = @ {
69
63
dataSourceDetails = @ {
@@ -73,14 +67,15 @@ function Test-AzDoServiceConnection {
73
67
}
74
68
75
69
$params = @ {
76
- uri = " $CollectionUri /$ProjectId /_apis/serviceendpoint/endpointproxy?endpointId=$ ( $connectioninfo.ServiceConnectionId ) &api-version=7.2-preview.1"
70
+ uri = " $CollectionUri /$ProjectName /_apis/serviceendpoint/endpointproxy?endpointId=$ ( $connectioninfo.ServiceConnectionId ) &api-version=7.2-preview.1"
77
71
Method = ' POST'
72
+ Headers = $script :header
78
73
body = $Body | ConvertTo-Json - Depth 99
79
74
ContentType = ' application/json'
80
75
}
81
76
82
77
if ($PSCmdlet.ShouldProcess ($ProjectName , " Test service connection on: $ ( $PSStyle.Bold ) $ProjectName $ ( $PSStyle.Reset ) " )) {
83
- $response = Invoke-RestMethod @Params
78
+ $result = Invoke-RestMethod @Params
84
79
if ($response.statusCode -eq ' badRequest' ) {
85
80
Write-Error " Connection $ ( $connectioninfo.ServiceConnectionName ) is not working: error $ ( $response.errorMessage ) "
86
81
} else {
0 commit comments