Is there any way to remove Build Artifact produced in one job of the pipeline, like:
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Agent.BuildDirectory)/${{ parameters.buildPath}}/'
artifact: 'RestoredBuilds'
publishLocation: 'pipeline'
to be re-used by another job. These files have no values outside of the pipeline and had better remove to empty space. If it is not possible, is there any other way of folders/files exchange between jobs of the same pipeline?
1
According to your description, you want to delete the Build Artifact produced in the pipeline while retaining the pipeline runs to avoid occupying the Azure Artifacts storage.
However, according to this Q&A, pipeline artifacts are not deletable or overwritable. Currently, you can only delete the pipeline run, and the pipeline artifacts will be deleted along with the run. You can set retention policies for builds, which will delete older runs to save storage space.
If it is not possible, is there any other way of folders/files exchange between jobs of the same pipeline?
-
Using a File Share for Artifact Exchange
You can publish the pipeline artifact to a file share that must be accessible from the pipeline agents. Then you can download the artifact in the subsequent jobs.
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Agent.BuildDirectory)/${{ parameters.buildPath}}/'
artifact: 'RestoredBuilds'
publishLocation: 'filepath'
fileSharePath: '\myshare(Build.DefinitionName)\(Build.BuildNumber)'
-
Using the Copy Files Task
You can use the Copy Files task to copy the files to a file share that must be accessible from the pipeline agents. Then you can copy the files back in the subsequent jobs.
- task: CopyFiles@2
inputs:
SourceFolder: '$(Agent.BuildDirectory)/${{ parameters.buildPath}}/'
Contents: '**'
TargetFolder: '\\network-share\path\to\folder'
-
Running Jobs on the Same Self-Hosted Agent
You can specify certain demands of the agent to make sure the pipeline jobs run on the same self-hosted agent. In the first job, you can copy and store the files to a path on the self-hosted agent, then in the subsequent jobs, you can access the path as they are run on the same agent.
pool:
name: Default
demands: SpecialCapabilities # exists check for capabilities