我創建了一個 powershell 腳本來在 Jenkins 中運行 DB2 查詢
withCredentials([usernamePassword(credentialsId: 'cred-id', usernameVariable: 'ID', passwordVariable: 'PASSWORD')]) {
$cn = new-object system.data.OleDb.OleDbConnection("Server=Server; Provider=IBMDADB2;DSN=DBName;User Id=$ID;Password=$PASSWORD");
$ds = new-object "System.Data.DataSet" "ds"
$q = "myQuery"
$da = new-object "System.Data.OleDb.OleDbDataAdapter" ($q, $cn)
$da.Fill($ds)
$cn.close()
}
如果我運行腳本并硬編碼我的憑據,它運行良好。
使用 withCredentials(),我收到以下錯誤:Security processing failed with reason "15" ("PROCESSING FAILURE")
根據一些研究,該錯誤似乎是因為 DB2 無法處理加密資料。有沒有辦法克服這個錯誤?
編輯:我試圖添加
$SecurePassword = ConvertTo-SecureString $PASSWORD -AsPlainText -Force
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
$UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
在我的 powershell 腳本的開頭,但即使在純文本中使用憑證作業正常,它仍然會引發相同的錯誤
uj5u.com熱心網友回復:
如果我正確理解Credentials Binding Jenkins 插件的檔案,呼叫中指定的變數將withCredentials()
成為環境變數,以便跨行程邊界使用它們。
請注意,這些環境變數的值未加密,因此目標行程不需要額外的(解密)作業。
因此,您需要使用$env:
[1]而不僅僅是$
在 PowerShell 中參考這些變數:
$cn = new-object system.data.OleDb.OleDbConnection "Server=Server; Provider=IBMDADB2;DSN=DBName;User Id=$env:ID;Password=$env:PASSWORD"
[1] 請參閱概念about_Environment_Variables幫助主題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/444134.html