ps/Modules/Cole.PowerShell.Developer/Public/Publish-TeamCityArtifact.ps1
2023-05-30 22:51:22 -07:00

42 lines
1.6 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function Publish-TeamCityArtifact {
<#
.SYNOPSIS
Publish an Artifact to the TeamCity job. This should be a file in a workspace folder that TeamCity can path to
.DESCRIPTION
The artifact gets published on the job so it can be viewed long-term. An example use-case would be publishing a json file generated during a build-step.
The artifact _may_ get stored on S3 by TeamCity automatically, but this function does not explicitly store the file on S3.
The artifact _may_ get purged by TeamCity processes automatically, if you need this artifact to be retained indefinitely you should use an alternate storage mechanism.
The function will attempt to test that the path exists. It will warn if the path does not exist/point to a valid file.
.PARAMETER Path
The path to the object
#>
[CmdletBinding()]
[OutputType([void])]
param (
[Parameter(Mandatory = $true)]
[string]$Path
)
$logLead = Get-LogLeadName
if (-not (Test-Path -Path $Path)) {
Write-Warning "$logLead : Could not resolve the path passed in, is it valid? [$Path]"
}
$charactersToEscape = @( "|", "'", "", "[", "]")
foreach ($character in $charactersToEscape) {
if ($Path -contains $character) {
Write-Warning "$logLead : Your path [$Path] contains a potentially invalid character. Pleae confirm it will work as expected. Character: $character"
}
}
if (Test-IsTeamCityProcess) {
Write-Host "##teamcity[publishArtifacts '$Path']"
} else {
Write-Host "$logLead : TeamCity should publish the artifact at [$Path]"
}
}