skip to Main Content

I’m getting an error FinalJob Job depends on unknown TestJob job

azure-pipelines.yml

- ${{ if eq(parameters.FLAG, false) }}:
  - job: TestJob
    displayName: Testing job
    dependsOn: AnotherJob
    condition: succeeded()
    steps:
     - checkout: none

     - template: my-template.yml
       parameters:
        TARGET: ${{ parameters.TARGET }}

- ${{ if eq(parameters.FLAG, true) }}:
  - job: TestJob2
    displayName: Testing job 2
    dependsOn: AnotherJob
    condition: succeeded()
    steps:
     - checkout: none

     - template: my-template2.yml
       parameters:
        TARGET: ${{ parameters.TARGET }}


- job: FinalJob
  displayName: Final Job..
  dependsOn: 
  - TestJob
  - TestJob2
  condition: |
   or
    (
      eq(dependencies.TestJob.result, 'Succeeded'),
      eq(dependencies.TestJob2.result, 'Succeeded')
    )
  steps:
   - checkout: none

   - task: Bash@3
     displayName: 'Final script'
     inputs:
      targetType: 'filePath'
      filePath: './scripts/my-script.sh'

What I would like?

I’d like to call FinalJob if TestJob or TestJob2 work properly. How can i do that? is it not working because the if before TestJob and TestJob2?

What I tried?

I made it work but adding my parameters.FLAG as part of the job condition.. but it displays the job name in azure platform and I don’t want that..

2

Answers


  1. I can reproduce the same issue when using the YAML sample.

    enter image description here

    The cause of the issue is that the dependsOn field will read the job name at the compile time.

    Since the if expression will let one of the job not be read at compile time, it will cause the unknown TestJob job issue.

    To solve this issue, I suggest that you can set a variable in YAML Pipeline to determine which job to run and use it in dependsOn field.

    For example:

    parameters:
    - name: FLAG
      type: string
      default: false
    
    
    variables:
    - ${{ if eq(parameters.FLAG, 'false') }}:
      - name: RunJob
        value: TestJob
    - ${{ if eq(parameters.FLAG, 'true') }}:
      - name: RunJob
        value: TestJob2
    jobs:
    - job: AnotherJob
      steps: 
      - script:  echo "123"
    
    
    - ${{ if eq(parameters.FLAG, false) }}:
      - job: TestJob
        displayName: Testing job
        dependsOn: AnotherJob
        condition: succeeded()
        steps:
         - checkout: none
    
         - template: my-template.yml
           parameters:
            TARGET: ${{ parameters.TARGET }}
    
    - ${{ if eq(parameters.FLAG, true) }}:
      - job: TestJob2
        displayName: Testing job 2
        dependsOn: AnotherJob
        condition: succeeded()
        steps:
         - checkout: none
    
         - template: my-template2.yml
           parameters:
            TARGET: ${{ parameters.TARGET }}
    
    
    - job: FinalJob
      displayName: Final Job..
      dependsOn: 
      -  ${{variables.RunJob}}
      condition: |
       or
        (
          eq(dependencies.TestJob.result, 'Succeeded'),
          eq(dependencies.TestJob2.result, 'Succeeded')
        )
      steps:
       - checkout: none
    
       - task: Bash@3
         displayName: 'Final script'
         inputs:
          targetType: 'filePath'
          filePath: './scripts/my-script.sh'
    

    Result:

    enter image description here

    Login or Signup to reply.
  2. I’d like to call FinalJob if TestJob or TestJob2 work properly. How can i do that?

    Two ways to get the goal, just simple-copy and try:

    method1.yml

    pool:
      vmImage: windows-latest
    
    jobs:
    - job: job1
      steps:
      - powershell: |
          Write-Output "hello from the job1"
    - job: job2
      steps:
      - powershell: |
          Write-Output "echo hello from the job1"
          exit 1
    - job: job3
      dependsOn:
      - job1
      - job2
      condition: or(succeeded('job1'), succeeded('job2'))
      steps:
      - powershell: |
          Write-Output "echo hello from the job3"
    

    method2.yml

    pool:
      vmImage: windows-latest
    
    jobs:
    - job: job1
      steps:
      - powershell: |
          Write-Output "your application steps in job1"
          Write-Output "##vso[task.setvariable variable=doThing;isOutput=true]Yes"
        name: job1var
    
    - job: job2
      steps:
      - powershell: |
          Write-Output "your application steps in job2"
          exit 1
          Write-Output "##vso[task.setvariable variable=doThing;isOutput=true]Yes"
        name: job2var
    
    - job: job3
      dependsOn:
      - job1
      - job2
      condition: or(eq(dependencies.job1.outputs['job1var.doThing'], 'Yes'), eq(dependencies.job2.outputs['job2var.doThing'], 'Yes'))
      steps:
      - powershell: |
          Write-Output "echo hello from the job3"
    

    here using exit 1 to simulate the job failure.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search