管道中的条件总是触发 "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') }}:
...
有:
An error occurred while loading the YAML build pipeline. Object reference not set to an instance of an object.
我几乎在使用 this example 的精简版。
我不确定它为什么会失败,因为在我看来它应该会通过。
关于如何解决这个问题或为什么会导致错误有什么建议吗?
终于想通了...
原来 ${{ }}
在 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..."
我有以下模板,应该设置它以便它始终通过,因为我只是在测试它:
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') }}:
...
有:
An error occurred while loading the YAML build pipeline. Object reference not set to an instance of an object.
我几乎在使用 this example 的精简版。
我不确定它为什么会失败,因为在我看来它应该会通过。
关于如何解决这个问题或为什么会导致错误有什么建议吗?
终于想通了...
原来 ${{ }}
在 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..."