jhurtas
jhurtas

Reputation: 694

Azure pipeline, muti stage YAML pipeline using same work directory on build server. How does it not corrupt

Clarifications and corrections:

We have Azure an azure devops YAML pipeline with multi stage and approvers. I noticed that running different build versions of the same pipeline uses the same work directory on the build server.

How does this not cause corruption of content, for example if the pipeline runs simultaneously for different build versions?

For example what if the newer pipeline run checks out source code while the other run is building and creating artifacts for its own version? I have checked the current path for two concurrent builds and it is the same.

Upvotes: 0

Views: 1514

Answers (1)

Walter
Walter

Reputation: 3058

What will happen if you run two commits in the same agent: Here is my example of multi-stage pipeline:

pool: Default
stages:
- stage: A
  jobs:
    - job: A
      steps:
      - task: PublishPipelineArtifact@1
        inputs:
          targetPath: '$(Build.SourcesDirectory)'
          artifact: 'drop'
          publishLocation: 'pipeline'

- stage: B
  jobs:
    - deployment: DeployWeb
      displayName: deploy Web App
      pool: Default
      workspace:
        clean: all
      environment: 'env'
      strategy:
        runOnce:
          deploy:
            steps:
            - checkout: self
            - task: CopyFiles@2
              inputs:
                SourceFolder: '$(Build.SourcesDirectory)'
                Contents: '**'
                TargetFolder: '$(Build.ArtifactStagingDirectory)'

I added a approve check in the environment. My running order is stage A(commit1)->stage A(commit2)->stage B(commit1)->stage B(commit2) .

  1. stage A(commit1): This job will checkout source code of commit1 and publish files in Sources Directory of commit1.
  2. stage A(commit2): This job will checkout source code of commit2 and publish files in Sources Directory of commit2.
  3. stage B(commit1): It is a deployment job and will not checkout resource by default.
    • The deployment job will download the artifact of commit1 as expected.
    • If I don't clean the workspace, it will continue to use the source code of commit2. This may cause some issues.
    • If I add a checkout step in this stage. It will checkout the source of commit1.

So you can add checkout step and clean workspace to the deployment jobs. Nondeployment jobs automatically check out source code and it will use the correct source.

Upvotes: 1

Related Questions