Reputation: 109
I'm creating a pipeline that uses 2 repositories. In the Build_Dev
stage, I only want to run it if it's from the repo Test
. However, every time the pipeline runs, the Build_Dev
stage is always skipped (although the commit is from Test
repo). Below is the yaml. What did I do wrong with the condition
in Build_Dev
stage? The Info stage recognizes$(Build.Repository.Name)
as Test
(which is correct).
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
Upvotes: 1
Views: 1405
Reputation: 7146
I can reproduce your issue.
You can use below method to get let the condition get the right value:
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
Above yaml file works fine on my side.
Upvotes: 1