Linter 規則 - 成品參數

此規則會驗證成品參數是否已正確定義。 必須符合下列條件,測試才會成功:

  • 如果您提供一個參數 (_artifactsLocation_artifactsLocationSasToken),則必須提供另一個參數。
  • _artifactsLocation 必須是字串。
  • 如果 _artifactsLocation 具有預設值,其必須是 deployment().properties.templateLink.uri 或其預設值的原始 URL。
  • _artifactsLocationSasToken 必須是安全字串。
  • 如果 _artifactsLocationSasToken 具有預設值,其必須是空字串。
  • 如果參考的模組具有 _artifactsLocation_artifactsLocationSasToken 參數,則即使這些參數在模組中具有預設值,也必須針對這些參數傳入一值。

Linter 規則程式碼

使用 Bicep 設定檔中的下列值來自訂規則設定:

artifacts-parameters

解決方案

下列範例未通過此測試,因為遺漏 _artifactsLocationSasToken

@description('The base URI where artifacts required by this template are located including a trailing \'/\'')
param _artifactsLocation string = deployment().properties.templateLink.uri

...

下一個範例會失敗此測試,因為在 _artifactsLocation 提供預設值時必須是 deployment().properties.templateLink.uri 或原始 URL,且的預設值 _artifactsLocationSasToken 不是空字串。

@description('The base URI where artifacts required by this template are located including a trailing \'/\'')
param _artifactsLocation string = 'something'

@description('SAS Token for accessing script path')
@secure()
param _artifactsLocationSasToken string = 'something'

...

此範例可通過此測試。

@description('The base URI where artifacts required by this template are located including a trailing \'/\'')
param _artifactsLocation string = deployment().properties.templateLink.uri

@description('SAS Token for accessing script path')
@secure()
param _artifactsLocationSasToken string = ''

...

下一步

如需 Linter 的詳細資訊,請參閱使用 Bicep Linter