![](/img/trans.png)
[英]AzCosmosDBSqlContainer : “Object reference not set to an instance of an object.”
[英]Conditional in pipeline always triggering “Object reference not set to an instance of an object.”
我有以下模板,應該設置它,因為我只是在測試它,所以它總是通過:
parameters:
- name: services
type: object
default:
- admin-v2
stages:
- stage: UnitTests
displayName: Run unit tests on service...
dependsOn: Changed
condition: succeeded()
jobs:
- job: UnitTests
condition: or(eq(stageDependencies.Changed.Changes.outputs['detectChanges.anyServicesChanged'], true), eq(variables['Build.Reason'], 'Manual'))
displayName: Running unit tests...
steps:
- ${{ each service in parameters.services }}:
${{ if eq(${{ service }}, 'admin-v2') }}:
- bash: |
echo "Now running ${{ service }} unit tests..."
以下行導致錯誤:
...
${{ if eq(${{ service }}, 'admin-v2') }}:
...
有:
加載 YAML 構建管道時出錯。 Object 引用未設置為 object 的實例。
我幾乎使用了這個例子的淡化版本。
我不確定它為什么會失敗,因為在我看來它肯定會通過。
有關如何解決此問題或為什么會導致錯誤的任何建議?
終於想通了...
原來${{ }}
在if
中不是必需的,這是我的疏忽。
所以它應該是:
parameters:
- name: services
type: object
default:
- admin-v2
stages:
- stage: UnitTests
displayName: Run unit tests on service...
dependsOn: Changed
condition: succeeded()
jobs:
- job: UnitTests
condition: or(eq(stageDependencies.Changed.Changes.outputs['detectChanges.anyServicesChanged'], true), eq(variables['Build.Reason'], 'Manual'))
displayName: Running unit tests...
steps:
- ${{ each service in parameters.services }}:
- ${{ if eq(service, 'admin-v2') }}:
- bash: |
echo "Now running ${{ service }} unit tests..."
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.