我想對於檢查出文件的生成創建腳本,編輯它,並檢查它放回PowerShell的/ VSTS建設 - 存儲憑證獨立/用戶的不可知論行書
我希望它在作爲開發人員運行時工作,或作爲構建代理工作。
我有一個類似於this的解決方案,其中密碼存儲在文件中併爲構建檢索。
即
文件創建:
read-host -prompt Password -assecurestring | convertfrom-securestring | out-file .\ps-password.pwd -ErrorAction Stop
文件使用:
# *VSTS Login*
$Username = $tfsUserName
$Password = Get-Content $tfsUserPasswordPath | ConvertTo-SecureString
$creds = New-Object -typename System.Management.Automation.PSCredential -ArgumentList $Username,$Password
$tfsServer = New-Object System.Uri("https://myaccount.visualstudio.com")
$tfsCollection = New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection($tfsServer,$creds)
$tfsCollection.Authenticate()
"***************** Authenticated *****************"
" *VSTS Check Out file* from $fileToUpdate"
Add-TfsPendingChange -Edit -Item $fileToUpdate -Verbose -ErrorAction Stop -wa 0
# read the file, update the number and save it back
$stuff = Get-Content $fileToUpdate
# modify stuff
Set-Content -Value $stuff -Path $fileToUpdate
# *VSTS Check In* Check in the file after changes.
" *VSTS Check In"
New-TfsChangeset -Item $fileToUpdate -Verbose -Comment "***NO_CI***" -Override true -ErrorAction Stop
SecureStrings
是基於機器上/用戶賬戶,所以當我從Powershell ISE
作爲運行生成正常工作我的帳戶,但不是從構建服務器觸發(它現在運行爲NetworkService
)。
我試過以下this post創建密碼文件爲'網絡服務',並嘗試key作爲安全字符串,但在我的用戶和網絡服務下無法獲得任何東西。
我該如何簡單地存儲將獨立運行腳本的用戶的憑據?
或者這只是錯誤的方式來做到這一點,我應該以某種方式使用PAT?
已經向上致謝,感謝您的幫助,但這似乎讓我陷入了一大堆其他問題。不確定這種方式是否與我現有的腳本兼容? – HockeyJ
拍攝你可能有的任何問題,我想你可以用這個令牌替換密碼,它應該可以工作。 –
賓果!這是答案。我已經用搜索者的最終腳本更新了你的答案。要等到我可以爲你添加+50賞金,那麼我會將其標記爲答案。謝謝! – HockeyJ