已跳过 Azure Pipeline 存储库名称条件

Azure Pipeline repo name condition skipped

我正在创建一个使用 2 个存储库的管道。在 Build_Dev 阶段,如果它来自 repo Test,我只想 运行 它。但是,每次管道 运行s,总是跳过 Build_Dev 阶段(尽管提交来自 Test repo)。下面是 yaml。我在 Build_Dev 阶段的 condition 做错了什么? Info 阶段将 $(Build.Repository.Name) 识别为 Test(这是正确的)。

resources:
  repositories:
  - repository: PipelineRepo
    type: git
    name: 'Test/pipeline-config'
  - repository: App
    type: git
    name: 'Test/Test'
    trigger:
    - Dev
    - Test*

stages:
- stage: Info
  displayName: Info
  jobs:
  - job: 'Info'
    displayName: 'Print Info: Repo: $(Build.Repository.Name) / Branch: $(Build.SourceBranch)'
    pool:
      vmImage: 'ubuntu-20.04'
    steps:
    - script: 'echo "Repo: $(Build.Repository.Name) / Branch: $(Build.SourceBranch)"'
      displayName: 'Write build info'

- stage: 'Build_Dev'
  dependsOn: Info
  displayName: 'Build the web application in Dev'
  condition: eq(variables['Build.Repository.Name'], 'Test')
  jobs:
  - job: 'Build'
    displayName: 'Build job'
    pool:
      vmImage: 'ubuntu-20.04'

    variables:
      dotnetSdkVersion: '5.x'

    steps:
    - checkout: App
    - task: UseDotNet@2
      displayName: 'Use .NET SDK $(dotnetSdkVersion)'
      inputs:
        version: '$(dotnetSdkVersion)'

    - script: 'echo "$(Build.DefinitionName), $(Build.BuildId), $(Build.BuildNumber), repo: $(Build.Repository.Name), branch: $(Build.SourceBranch)"'
      displayName: 'Write build info'

    - task: DotNetCoreCLI@2
      displayName: 'Restore project dependencies'
      inputs:
        command: 'restore'
        projects: '**/*.csproj'

    - task: DotNetCoreCLI@2
      displayName: 'Build the project - Dev'
      inputs:
        command: 'build'
        arguments: '--no-restore'
        projects: '**/*.csproj'

    - task: DotNetCoreCLI@2
      displayName: 'Publish the project - Dev'
      inputs:
        command: 'publish'
        projects: '**/*.csproj'
        publishWebProjects: false
        arguments: '--no-build --output $(Build.ArtifactStagingDirectory)/Dev'
        zipAfterPublish: true

    - publish: '$(Build.ArtifactStagingDirectory)'
      artifact: drop

docs来看,我觉得是这个原因:

我可以重现你的问题。

您可以使用以下方法让条件获得正确的值:

stages:
- stage: A
  jobs:
  - job: A1
    steps:
     - bash: echo "##vso[task.setvariable variable=reponame;isOutput=true]$(build.repository.name)"
     # or on Windows:
     # - script: echo ##vso[task.setvariable variable=shouldrun;isOutput=true]true
       name: printvar

- stage: B
  condition: eq(dependencies.A.outputs['A1.printvar.reponame'], 'YourRepoName')
  dependsOn: A
  jobs:
  - job: B1
    steps:
    - script: echo hello from Stage B

上面的 yaml 文件在我这边工作正常。