mirror of
https://github.com/snazy2000/SnipeitPS.git
synced 2025-12-15 18:55:47 +00:00
Change Gitlab CI build
This commit is contained in:
parent
cf23662a42
commit
7606d2d7a9
4 changed files with 112 additions and 20 deletions
|
|
@ -1,26 +1,18 @@
|
||||||
variables:
|
|
||||||
GIT_SSL_NO_VERIFY: "true"
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null
|
|
||||||
- Install-Module InvokeBuild, BuildHelpers, PSScriptAnalyzer -force -Scope CurrentUser
|
|
||||||
- Install-Module Pester -Force -SkipPublisherCheck -Scope CurrentUser
|
|
||||||
- Import-Module PSScriptAnalyzer -Scope CurrentUser
|
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
# - release
|
# - release
|
||||||
|
|
||||||
ps_scriptanalyzer:
|
variables:
|
||||||
|
GIT_SSL_NO_VERIFY: "true"
|
||||||
|
ErrorActionPreference: STOP
|
||||||
|
|
||||||
|
Test:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- $res = (Invoke-ScriptAnalyzer -Path . -Severity Error).count
|
- .\build.ps1 -Tasks 'analyze','test'
|
||||||
- if ($res -gt 0) { throw "$($res) Analytics failed."}
|
except:
|
||||||
tags:
|
- master
|
||||||
- powershell
|
|
||||||
|
|
||||||
# except:
|
|
||||||
# - master
|
|
||||||
#Release:
|
#Release:
|
||||||
# stage: release
|
# stage: release
|
||||||
# script:
|
# script:
|
||||||
|
|
|
||||||
39
SnipeitPS/Public/Get-Supplier.ps1
Normal file
39
SnipeitPS/Public/Get-Supplier.ps1
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
# Gets a list of Snipe-it Suppliers
|
||||||
|
|
||||||
|
.PARAMETER url
|
||||||
|
URL of Snipeit system, can be set using Set-Info command
|
||||||
|
|
||||||
|
.PARAMETER apiKey
|
||||||
|
Users API Key for Snipeit, can be set using Set-Info command
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Get-Supplier -url "https://assets.example.com" -token "token..."
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Get-Supplier -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "MySupplier" }
|
||||||
|
|
||||||
|
#>
|
||||||
|
|
||||||
|
function Get-Supplier()
|
||||||
|
{
|
||||||
|
Param(
|
||||||
|
[parameter(mandatory=$true)]
|
||||||
|
[string]$url,
|
||||||
|
|
||||||
|
[parameter(mandatory=$true)]
|
||||||
|
[string]$apiKey
|
||||||
|
)
|
||||||
|
|
||||||
|
$Parameters = @{
|
||||||
|
Uri = "$url/api/v1/suppliers"
|
||||||
|
Method = 'Get'
|
||||||
|
Token = $apiKey
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = Invoke-SnipeitMethod @Parameters
|
||||||
|
|
||||||
|
$result
|
||||||
|
}
|
||||||
|
|
||||||
Binary file not shown.
61
build.ps1
Normal file
61
build.ps1
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
param(
|
||||||
|
[string[]]$Tasks
|
||||||
|
)
|
||||||
|
|
||||||
|
function Install-Dependency([string] $Name)
|
||||||
|
{
|
||||||
|
$policy = Get-PSRepository -Name "PSGallery" | Select-Object -ExpandProperty "InstallationPolicy"
|
||||||
|
if($policy -ne "Trusted") {
|
||||||
|
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(Get-Module -Name $Name -ListAvailable)) {
|
||||||
|
Install-Module -Name $Name -Scope CurrentUser
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Analyze-Scripts
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[string]$Path = "$PSScriptRoot\SnipeitPS\"
|
||||||
|
)
|
||||||
|
$result = Invoke-ScriptAnalyzer -Path $Path -Severity @('Error', 'Warning') -Recurse
|
||||||
|
if ($result) {
|
||||||
|
$result | Format-Table
|
||||||
|
Write-Error -Message "$($result.SuggestedCorrections.Count) linting errors or warnings were found. The build cannot continue."
|
||||||
|
EXIT 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Run-Tests
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[string]$Path = "$PSScriptRoot\SnipeitPS"
|
||||||
|
)
|
||||||
|
|
||||||
|
$results = Invoke-Pester -Path $Path -PassThru
|
||||||
|
if($results.FailedCount -gt 0) {
|
||||||
|
Write-Output " > $($results.FailedCount) tests failed. The build cannot continue."
|
||||||
|
foreach($result in $($results.TestResult | Where {$_.Passed -eq $false} | Select-Object -Property Describe,Context,Name,Passed,Time)){
|
||||||
|
Write-Output " > $result"
|
||||||
|
}
|
||||||
|
|
||||||
|
EXIT 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($task in $Tasks){
|
||||||
|
switch($task)
|
||||||
|
{
|
||||||
|
"analyze" {
|
||||||
|
Install-Dependency -Name "PSScriptAnalyzer"
|
||||||
|
Write-Output "Analyzing Scripts..."
|
||||||
|
Analyze-Scripts
|
||||||
|
}
|
||||||
|
"test" {
|
||||||
|
Install-Dependency -Name "Pester"
|
||||||
|
Write-Output "Running Pester Tests..."
|
||||||
|
Run-Tests
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue