在 Azure Pipeline 中删除 Azure Key Vault 机密失败

Deleting Azure Key Vault secret fails in Azure Pipeline

我正在尝试使用 Azure Pipeline 删除 Azure Key Vault 中的机密。 Key Vault 启用了软删除并禁用了清除保护。我想删除机密,然后在以后的任务中清除机密。

我使用以下任务:

- task: AzureCLI@2
      displayName: 'Delete <secret> from Azure Key Vault'
      inputs:
        azureSubscription: <Valid service connection>
        scriptType: 'pscore'
        scriptLocation: 'inlineScript'
        inlineScript: 'az keyvault secret delete --name "<secret name>" --vault-name "<Key Vault Name>"'
        failOnStandardError: true

当我执行此操作时,机密被删除但任务失败并显示以下内容:

{
  "attributes": {
    "created": "2022-03-03T08:16:55+00:00",
    "enabled": true,
    "expires": null,
    "notBefore": null,
    "recoveryLevel": "Recoverable+Purgeable",
    "updated": "2022-03-03T08:16:55+00:00"
  },
  "contentType": null,
  "deletedDate": "2022-03-03T09:44:49+00:00",
  "id": "https://<vault name>.vault.azure.net/secrets/<secret name>/<ID>",
  "kid": null,
  "managed": null,
  "name": "<secret name>",
  "recoveryId": "https://<vault name>.vault.azure.net/deletedsecrets/<secret name>",
  "scheduledPurgeDate": "2022-06-01T09:44:49+00:00",
  "tags": null,
  "value": null
}

##[error]WARNING: Warning! If you have soft-delete protection enabled on this key vault, this secret will be moved to the soft deleted state. You will not be able to create a secret with the same name within this key vault until the secret has been purged from the soft-deleted state. Please see the following documentation for additional guidance. https://docs.microsoft.com/azure/key-vault/general/soft-delete-overview

##[error]Script has output to stderr. Failing as failOnStdErr is set to true.

当错误实际上只是一个警告时,为什么脚本会失败? 有什么解决办法吗?

它失败了,因为错误被写入了 stderr,并且您在任务上启用了 failOnStandardError。 您无法更改任务写入警告的方式,但可以将 failOnStandardError 设置为 false。 如果命令 returns a non-zero 退出代码,任务仍然会失败。