在Azure Pipeline中读取KeyVault Secret
我正在尝试在CICD管道中运行NPM测试,并且该测试需要阅读一些秘密,因此当我尝试运行my_secret = $(my-secret)NPM测试时;它可以按照我在Azure Pipeline变量部分中定义此秘密的方式工作,其值。但是我很少有50多个秘密的应用程序,而且我认为这是一个更好的解决方案,因此我尝试在Azure DevOps中编辑管道并使用了Azure钥匙库。我提供了服务连接,钥匙库,并更新了管道yaml。但是我仍然看不到成功的NPM测试输出。我试图回应钥匙vault的秘密之一,我想我仍然表现为秘密是正确的。
这就是我通过在变量中添加秘密及其价值并运行my_secret = $(my-secret)npm测试的方法,这可以正常工作 https://i.sstatic.net/z9e1g.png 。 但是,当我尝试在Azure DevOps中使用Azure键值添加时: https://i.sstatic.net/rlqec.png
- task: AzureKeyVault@2
inputs:
azureSubscription: 'keyvaultsp'
KeyVaultName: 'mykeyvault'
SecretsFilter: '*'
RunAsPreJob: true
NPM测试失败了阅读这些秘密要通过。
Error:
at Object.isEmpty (/home/vsts/work/1/s/lib/utilities/index.js:495:192)
at new OTPMAdaptor (/home/vsts/work/1/s/lib/adaptors/communication/otpm.js:23:197)
at new OtpService (/home/vsts/work/1/s/lib/services/otp.js:13:97)
at Array.forEach (<anonymous>)
server.registerService() called by haute using /home/vsts/work/1/s/lib/services/otp.js: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at Object.isEmpty (/home/vsts/work/1/s/lib/utilities/index.js:495:192)
at new OTPMAdaptor (/home/vsts/work/1/s/lib/adaptors/communication/otpm.js:23:197)
at new OtpService (/home/vsts/work/1/s/lib/services/otp.js:13:97)
at Array.forEach (<anonymous>)
server.registerService() called by haute using /home/vsts/work/1/s/lib/services/otp.js: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at Object.isEmpty (/home/vsts/work/1/s/lib/utilities/index.js:495:192)
at new OTPMAdaptor (/home/vsts/work/1/s/lib/adaptors/communication/otpm.js:23:197)
at new OtpService (/home/vsts/work/1/s/lib/services/otp.js:13:97)
at Array.forEach (<anonymous>)
server.registerService() called by haute using /home/vsts/work/1/s/lib/services/otp.js: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at Object.isEmpty (/home/vsts/work/1/s/lib/utilities/index.js:495:192)
at new OTPMAdaptor (/home/vsts/work/1/s/lib/adaptors/communication/otpm.js:23:197)
at new OtpService (/home/vsts/work/1/s/lib/services/otp.js:13:97)
at Array.forEach (<anonymous>)
npm ERR! Test failed. See above for more details.
##[error]Bash exited with code '1'.
Finishing: Testing
I am trying to run npm test in my cicd pipeline and this test needs to read some secrets hence when I try to run MY_Secret=$(MY-Secret) npm test ; it works as I have defined this secret in my Azure pipeline variable section with its value. But I have few applications with more than 50 secrets and I don't think this is a better solution hence I tried to edit my pipeline in Azure Devops and used Azure Key Vault. I provided the service connection ,key vault and updated my pipeline yaml. But I am still not able to see successful npm test output. I tried to echo one of the secret from my keyvault and I guess I is correct to still show as secret.
This is how I tried by adding secret and its value in variable and running MY_Secret=$(MY-Secret) npm test , this works fine https://i.sstatic.net/Z9E1G.png.
But when I tried using adding azure key vault in azure devops:
https://i.sstatic.net/RLQEc.png
- task: AzureKeyVault@2
inputs:
azureSubscription: 'keyvaultsp'
KeyVaultName: 'mykeyvault'
SecretsFilter: '*'
RunAsPreJob: true
The npm test got failed which needs to read those secrets to pass.
Error:
at Object.isEmpty (/home/vsts/work/1/s/lib/utilities/index.js:495:192)
at new OTPMAdaptor (/home/vsts/work/1/s/lib/adaptors/communication/otpm.js:23:197)
at new OtpService (/home/vsts/work/1/s/lib/services/otp.js:13:97)
at Array.forEach (<anonymous>)
server.registerService() called by haute using /home/vsts/work/1/s/lib/services/otp.js: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at Object.isEmpty (/home/vsts/work/1/s/lib/utilities/index.js:495:192)
at new OTPMAdaptor (/home/vsts/work/1/s/lib/adaptors/communication/otpm.js:23:197)
at new OtpService (/home/vsts/work/1/s/lib/services/otp.js:13:97)
at Array.forEach (<anonymous>)
server.registerService() called by haute using /home/vsts/work/1/s/lib/services/otp.js: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at Object.isEmpty (/home/vsts/work/1/s/lib/utilities/index.js:495:192)
at new OTPMAdaptor (/home/vsts/work/1/s/lib/adaptors/communication/otpm.js:23:197)
at new OtpService (/home/vsts/work/1/s/lib/services/otp.js:13:97)
at Array.forEach (<anonymous>)
server.registerService() called by haute using /home/vsts/work/1/s/lib/services/otp.js: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at Object.isEmpty (/home/vsts/work/1/s/lib/utilities/index.js:495:192)
at new OTPMAdaptor (/home/vsts/work/1/s/lib/adaptors/communication/otpm.js:23:197)
at new OtpService (/home/vsts/work/1/s/lib/services/otp.js:13:97)
at Array.forEach (<anonymous>)
npm ERR! Test failed. See above for more details.
##[error]Bash exited with code '1'.
Finishing: Testing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论