Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- AzureDevOpsDsc
- Updated pipeline files to support change of default branch to main.
- Added GitHub issue templates and pull request template ([issue #1](https://github.com/dsccommunity/AzureDevOpsDsc/issues/1))
- Added GitHub issue templates and pull request template
([issue #1](https://github.com/dsccommunity/AzureDevOpsDsc/issues/1))
- Added the `AzDevOpsProject`, DSC Resource
- Fixed non-terminating, integration tests ([issue #18](https://github.com/dsccommunity/AzureDevOpsDsc/issues/18))
- AzureDevOpsDsc.Common
- Added 'wrapper' functionality around the [Azure DevOps REST API](https://docs.microsoft.com/en-us/rest/api/azure/devops/)
10 changes: 6 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ development), the following actions need to be performed:
initiated.

* You need to set the following environment variables so the build will determine
it needs to execute the Integration tests, and it has the Personal Access Token
(PAT) and API URI
it needs to execute the Integration tests, and it can use the [Personal Access Token
(PAT)](https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page)
and API URI

```Powershell
$env:CI = $true
$env:AZUREDEVOPSINTEGRATIONAPIURI = 'YourApiUriHere'
$env:AZUREDEVOPSINTEGRATIONPAT = 'YourPatHere'
$env:CONFIGURATION = 'Integration'
$env:AZUREDEVOPSINTEGRATIONAPIURI = 'YourApiUriHere' # IMPORTANT: Ensure this is a destructable organization/collection
$env:AZUREDEVOPSINTEGRATIONPAT = 'YourPatHere' # This PAT must have access to update resources
```

>**Important**: It is not recommended to store any Personal Access Token (PAT)
Expand Down
9 changes: 6 additions & 3 deletions source/Classes/001.DscResourceBase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class DscResourceBase

if ([String]::IsNullOrWhiteSpace($dscResourceKeyPropertyName))
{
throw "Cannot obtain a 'DscResourceKey' value for the '$($this.GetType().Name)' instance."
$errorMessage = "Cannot obtain a 'DscResourceKey' value for the '$($this.GetType().Name)' instance."
New-InvalidOperationException -Message $errorMessage
}

return $this."$dscResourceKeyPropertyName"
Expand Down Expand Up @@ -37,12 +38,14 @@ class DscResourceBase

if ($null -eq $dscResourceKeyPropertyNames -or $dscResourceKeyPropertyNames.Count -eq 0)
{
throw "Could not obtain a 'DscResourceDscKey' property for type '$($this.GetType().Name)'."
$errorMessage = "Could not obtain a 'DscResourceDscKey' property for type '$($this.GetType().Name)'."
New-InvalidOperationException -Message $errorMessage

}
elseif ($dscResourceKeyPropertyNames.Count -gt 1)
{
throw "Obtained more than 1 property for type '$($this.GetType().Name)' that was marked as a 'Key'. There must only be 1 property on the class set as the 'Key' for DSC."
$errorMessage = "Obtained more than 1 property for type '$($this.GetType().Name)' that was marked as a 'Key'. There must only be 1 property on the class set as the 'Key' for DSC."
New-InvalidOperationException -Message $errorMessage
}

return $dscResourceKeyPropertyNames[0]
Expand Down
24 changes: 17 additions & 7 deletions source/Classes/003.AzDevOpsDscResourceBase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class AzDevOpsDscResourceBase : AzDevOpsApiDscResourceBase
$thisType = $this.GetType()
if ($thisType -eq [AzDevOpsDscResourceBase])
{
throw "Method 'GetCurrentState()' in '$($thisType.Name)' must be overidden and called by an inheriting class."
$errorMessage = "Method 'GetCurrentState()' in '$($thisType.Name)' must be overidden and called by an inheriting class."
New-InvalidOperationException -Message $errorMessage
}
return $null
}
Expand Down Expand Up @@ -143,8 +144,8 @@ class AzDevOpsDscResourceBase : AzDevOpsApiDscResourceBase

if ($($currentProperties[$_].ToString()) -ne $($desiredProperties[$_].ToString()))
{
throw "The '$($this.GetType().Name)', DSC Resource does not support changes for/to the '$_' property."
break
$errorMessage = "The '$($this.GetType().Name)', DSC Resource does not support changes for/to the '$_' property."
New-InvalidOperationException -Message $errorMessage
}
}
}
Expand Down Expand Up @@ -188,8 +189,8 @@ class AzDevOpsDscResourceBase : AzDevOpsApiDscResourceBase
break
}
default {
throw "Could not obtain a valid 'Ensure' value within 'AzDevOpsProject' Test() function. Value was '$($desiredProperties.Ensure)'."
return [RequiredAction]::Error
$errorMessage = "Could not obtain a valid 'Ensure' value within '$($this.GetResourceName())' Test() function. Value was '$($desiredProperties.Ensure)'."
New-InvalidOperationException -Message $errorMessage
}
}

Expand Down Expand Up @@ -258,7 +259,8 @@ class AzDevOpsDscResourceBase : AzDevOpsApiDscResourceBase
}
else
{
throw "A required action of '$RequiredAction' has not been catered for in GetDesiredStateParameters() method."
$errorMessage = "A required action of '$RequiredAction' has not been catered for in GetDesiredStateParameters() method."
New-InvalidOperationException -Message $errorMessage
}


Expand All @@ -273,7 +275,15 @@ class AzDevOpsDscResourceBase : AzDevOpsApiDscResourceBase

[System.Boolean] Test()
{
return $this.TestDesiredState()
# TestDesiredState() will throw an exception in certain expected circumstances. Return $false if this occurs.
try
{
return $this.TestDesiredState()
}
catch
{
return $false
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ try


It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True'
}
}

Expand Down Expand Up @@ -156,7 +156,7 @@ try


It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True'
}
}

Expand Down Expand Up @@ -201,9 +201,9 @@ try
} | Should -Not -Throw
}

It 'Should return $false or $null when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -BeIn @('False',$null)
}
It 'Should return $false or $null when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'False'
}
}


Expand Down Expand Up @@ -258,7 +258,7 @@ try


It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True'
}
}

Expand Down Expand Up @@ -315,7 +315,7 @@ try


It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True'
}
}

Expand Down Expand Up @@ -375,7 +375,7 @@ try


It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True'
}
}

Expand Down Expand Up @@ -421,7 +421,7 @@ try
}

It 'Should return $false or $null when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -BeIn @('False',$null)
Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'False'
}
}

Expand Down Expand Up @@ -477,7 +477,7 @@ try


It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True'
}
}

Expand Down Expand Up @@ -538,7 +538,7 @@ try


It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True'
}

}
Expand Down Expand Up @@ -599,7 +599,7 @@ try


It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True'
}
}

Expand Down Expand Up @@ -659,7 +659,7 @@ try


It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True'
}
}

Expand Down Expand Up @@ -716,7 +716,7 @@ try


It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True'
}
}

Expand Down