Clean All build directories in Azure DevOps Pipeline settings is not working while using YAML configuration
Asked Answered
P

3

5

I use Azure DevOps for some time, and I always use Classic Editor GUI when crafting Build Pipeline. Now I'm trying to create new pipeline using YAML. Everything went well and the build was successful. But, I have noticed different behavior in checkout task compared to pipeline using Classic Editor. In both pipelines, settings used in 'Get sources' tab are same(see the below screenshot)

enter image description here

In case of Classic Editor pipeline, checkout task Deletes and recreates $(Agent.BuildDirectory). This results in initializing a new, local Git repository for every build. But, for YAML pipeline, checkout task only performing a git clean -ffdx and removing source directories only. How to resolve this issue for YAML pipelines?

YAML pipeline log:

enter image description here

Classic Editor pipeline log:

enter image description here

Paraph answered 8/5, 2020 at 10:14 Comment(0)
P
13

Setting clean all build directories option(in below screenshot) in devops UI is not working in case of YAML builds.

enter image description here

But you can specify this in YAML file itself by using the workspace setting of a Job. This is working as expected.

jobs:
- job: Job1
  workspace:
    clean: all # what to clean up before the job runs - outputs | resources | all
Paraph answered 12/5, 2020 at 10:5 Comment(1)
Thanks for sharing your solution here, would you please accept your solution as the answer? So it would be helpful for other members who get the same issue to find the solution easily. Have a nice day:)Ambiversion
L
1

It is really strange because I have this (in YAML build)

enter image description here

I found this in documentation:

When clean is set to true the build pipeline performs an undo of any changes in $(Build.SourcesDirectory). More specifically, the following Git commands are executed prior to fetching the source.

git clean -ffdx
git reset --hard HEAD

Do you have clean option enabled?

Luo answered 8/5, 2020 at 11:23 Comment(3)
What should be the issue? Where should I need to check.. in the YAML file or Pipeline settings... do you have any suggestions?Paraph
Have no idea. I just created a pipeline to check it. I didn't do anything special to get this. Can you create a new pipeline and check this? How old is your organisation?Luo
Yes. I have checked with a new pipeline. For the first run, I'm getting this logs and git initialisation is happening. But from second run, checkout task only performing a git clean -ffdx only. Means, for every build it's not initialising a new local repo. This is the issue I'm facing.Paraph
E
0

It will work ONLY if you will add this task to the YAML file where your pipeline is defined:

- task: PostBuildCleanup@3

If this task is added and Clean is set to false inside 'Get sources' tab -> it will delete $(Agent.BuildDirectory) ( not just sourcesc directory which is ussualy "s" dir, but the artifacts "a" dir and binary "b" dir as well )

From 'Get sources' tab you can fine tune what to delete by setting Clean option to "true" and choosing between available options ( sources dir, sources dir and binary dir, all directories ... )

If your build uses a Git repository, a minimal portion of the .git folder will remain on disk. Those remaining files are needed by the build agent's built-in Post Job Cleanup.

Espinal answered 1/6, 2023 at 11:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.