1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| function Invoke-ContainerPipeline { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string]$ImageName, [string]$DockerfilePath = './Dockerfile' )
$report = [PSCustomObject]@{ Timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss' BuildLog = @() DeploymentStatus = @() }
$buildOutput = docker build -t $ImageName -f $DockerfilePath . 2>&1 $report.BuildLog += $buildOutput
if ($LASTEXITCODE -eq 0) { $pushOutput = docker push $ImageName 2>&1 $report.BuildLog += $pushOutput }
if ($LASTEXITCODE -eq 0) { $k8sOutput = kubectl apply -f deployment.yaml 2>&1 $report.DeploymentStatus += [PSCustomObject]@{ Cluster = (kubectl config current-context) Status = if($LASTEXITCODE -eq 0){'Success'}else{'Failed'} Output = $k8sOutput } }
$htmlReport = $report | ConvertTo-Html -Fragment $htmlReport | Out-File "$env:TEMP/ContainerReport_$(Get-Date -Format yyyyMMdd).html" return $report }
|