46 lines
1.7 KiB
YAML
46 lines
1.7 KiB
YAML
# Spiegelt dieses Repo nach Gitea (echte Branches/Tags) bei jedem Push.
|
|
# Gitea-Push-Token liegt geschuetzt in C:\agent-secrets\gitea_push_token.txt (nur Agent-Dienst lesbar).
|
|
trigger:
|
|
branches:
|
|
include:
|
|
- '*'
|
|
|
|
pool:
|
|
name: 'Default'
|
|
|
|
variables:
|
|
GITEA_HOST: 'git.wvds.it'
|
|
GITEA_ORG: 'wvds-public'
|
|
TOKEN_FILE: 'C:\agent-secrets\gitea_push_token.txt'
|
|
|
|
steps:
|
|
- checkout: none
|
|
|
|
- powershell: |
|
|
$ErrorActionPreference = 'Stop'
|
|
$repoName = "$(Build.Repository.Name)"
|
|
$devopsUrl = "$(Build.Repository.Uri)"
|
|
|
|
if (-not (Test-Path "$(TOKEN_FILE)")) { Write-Error "Token-Datei fehlt: $(TOKEN_FILE)"; exit 1 }
|
|
$tok = (Get-Content "$(TOKEN_FILE)" -Raw).Trim()
|
|
if ([string]::IsNullOrEmpty($tok)) { Write-Error "Token leer"; exit 1 }
|
|
Write-Host "Gitea-Token geladen (Laenge $($tok.Length))"
|
|
|
|
$work = Join-Path "$(Agent.TempDirectory)" "mirror-src"
|
|
if (Test-Path $work) { Remove-Item -LiteralPath $work -Recurse -Force }
|
|
|
|
$srcAuth = $devopsUrl -replace '^https://', "https://devops:$($env:SYSTEM_ACCESSTOKEN)@"
|
|
Write-Host "Klone Mirror aus DevOps: $repoName"
|
|
git clone --mirror "$srcAuth" "$work"
|
|
if ($LASTEXITCODE -ne 0) { Write-Error "clone --mirror fehlgeschlagen"; exit 1 }
|
|
|
|
$target = "https://devops-mirror:$tok@$($env:GITEA_HOST)/$($env:GITEA_ORG)/$repoName.git"
|
|
Write-Host "Pushe Mirror nach https://$($env:GITEA_HOST)/$($env:GITEA_ORG)/$repoName"
|
|
Set-Location $work
|
|
git push --mirror "$target"
|
|
if ($LASTEXITCODE -ne 0) { Write-Error "push --mirror fehlgeschlagen"; exit 1 }
|
|
Write-Host "Spiegelung erfolgreich."
|
|
displayName: 'Mirror to Gitea'
|
|
env:
|
|
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
|