如何避免在 Azure Agent for Pipeline in Environment 中创建新文件夹

How to avoid creating new folder in Azure Agent for Pipeline in Environment

我已经为虚拟机创建了一个 Azure 代理环境,我在其中将构建下载到文件夹。我有以下 yaml 文件

# Python package
# Create and test a Python package on multiple Python versions. OK
# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/python

trigger:
  paths:
    include:
      - Flytteordre

pool:
  vmImage: 'ubuntu-latest'
  name: Azure Pipelines
variables:
  python.version: '3.6'

stages:
- stage: Build
  displayName: Build stage
  jobs:
  - job: build
    displayName: build
    steps:
    - task: UsePythonVersion@0
      displayName: 'Use Python $(python.version) copy'
      inputs:
        versionSpec: '$(python.version)'
    
    # We actually don't need to install these dependencies here. It needs to happen in the deploy yaml file.
    - task: CmdLine@2 
      inputs:
        script: |
          python -m pip install --upgrade pip 
          python -m pip install selenium 
          python -m pip install pdfplumber 
          python -m pip install pandas
      displayName: 'Install dependencies'
    
    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifact: dist'
      inputs:
        PathtoPublish: Flytteordre
        ArtifactName: dist

- stage: Deployment
  displayName: Deployment stage
  jobs:
    - deployment: deploymentJob
      displayName: Deploy
      environment:
       name: Production
       resourceType: VirtualMachine
      strategy:
       runOnce:
         deploy:
           steps:
           - download: none
           - downloadBuild: none
           - task: DownloadBuildArtifacts@0
             inputs:
               buildType: 'current'
               downloadType: 'single'
               artifactName: 'dist'
               downloadPath: 'C:/azagent/A1/_work/myfolder/'

我的问题是,每次我 运行 管道时,它都会在 _work 环境中创建一个名为 1、2 等的文件夹。

我想避免这种情况,以便我可以完全控制创建哪些文件夹。如您所见,我已指出我的工件应下载到文件夹路径 C:/azagent/A1/_work/myfolder/,但这将创建两个文件夹。一个是我指定的文件夹,另一个是标题为数字的文件夹。我现在这是默认设置,但我想知道是否有办法关闭此默认设置或至少能够更改预定义路径变量 PIPELINE.WORKSPACE 或 Agent.BuildDirectory?

How to avoid creating new folder in Azure Agent for Pipeline in Environment

根据文档Agent variables

因此,每个构建定义都进入代理工作目录中自己的目录。

众所周知,管道有输入和输出。每当我们创建一个新的管道时,我们都会增加一个数字来命名创建的新工作文件夹。这样做的好处是多个 运行 共享同一个存储库副本的构建迟早会相互踩踏。

I would prefer the option of being able to name the directory myself in case I need to find a particular project and open it on the local agent.

如果你想在本地代理上打开它,你可以直接使用代理变量来显示路径:

Agent.BuildDirectory