Miguel Moura
Miguel Moura

Reputation: 39384

Job starts before previous job finishes

I have an Azure Pipelines stage with two jobs (job: Publish and deployment: Deploy).

Sometimes the job deployment: Deploy starts running before job: Publish finishes.

I get an error and then I need to wait to job: Publish finishes and rerun deployment: Deploy.

When I rerun deployment: Deploy everything goes well ...

Question
Why does deployment: Deploy starts before job: Publish finishes?

Here is the YML code for that stage:

- stage: Production
  dependsOn: Staging
  jobs:
  - job: Publish
    pool:
      vmImage: 'Ubuntu 16.04'
    steps:
    - task: UseDotNet@2
      displayName: Setup
      inputs:
        packageType: sdk
        version: 3.0.x
    - task: DotNetCoreCLI@2
      displayName: Publish
      inputs:
        command: publish
        publishWebProjects: false
        projects: 'src/**/*.csproj'
        arguments: '--configuration production --output $(Build.ArtifactStagingDirectory)'
        zipAfterPublish: true
    - task: PublishPipelineArtifact@0
      displayName: Export
      inputs:
        artifactName: Production
        targetPath: '$(Build.ArtifactStagingDirectory)'
  - deployment: Deploy
    pool:
      vmImage: Ubuntu-16.04
    environment: production
    strategy:
      runOnce:
        deploy:
          steps:
          - task: DownloadPipelineArtifact@1
            displayName: Import
            inputs:
              artifactName: Production
          - task: AzureRmWebAppDeployment@3
            displayName: Api
            inputs:
              package: '$(Build.ArtifactStagingDirectory)/Api.zip'
              removeAdditionalFilesFlag: true
              azureSubscription: '$(azure.subscription)'
              appType: 'Web App on Linux'
              webAppName: 'app-api'

Upvotes: 2

Views: 5280

Answers (1)

Mengdi Liang
Mengdi Liang

Reputation: 18978

Because when the syntax you are using does not include job dependency, at this time, it is the one which would build in parallel (no dependencies).

If you do not specified dependency and the actual organization situation allows parallelism, these jobs will run in parallel.

BUT, if org itself does not meet the parallel conditions, also the user does not specify the job order (dependency). Now the server will run the job randomly. Because the jobs which without dependency relationship are two separate jobs for the server.

Note: This only occur with YAML schema, Classic editor has default execution order.


To solve the trouble you were, just add dependsOn: Publish in your deployment: Deploy job:

  - deployment: Deploy
    dependsOn: Publish
    pool:
      vmImage: Ubuntu-16.04
    environment: production

Now, the deployment: Deploy will only run after the job: Publish finished.

Upvotes: 5

Related Questions