本地服务器上的 Azure Pipeline 复制文件任务

问题描述 投票:0回答:1

我从 azure devops 开始 我有一个本地代理,想要更新 powershell 脚本。 创建存储库并上传文件。 使用 vscode,创建本地文件夹并克隆存储库 当我修改文件时,我想提交到存储库,并将文件复制到 Windows 服务器。

  • 任务:复制文件@2 输入:

               SourceFolder: '\\machines\folder'
               Contents: '*.ps1'  # Adjust the pattern as needed
               TargetFolder: '\\server\DevOps'
               CleanTargetFolder: true  # Optional: Clean existing files in the target folder
               OverWrite: true  # Optional: Replace existing files
    

我似乎无法获取从源文件夹复制文件的命令 - 这是第 1 步

但是,之后我希望能够让其他人使用此管道来复制他们修改过的文件,我如何将源文件夹设置为用户自己在 vscode 中克隆的文件夹?

我尝试按照上面的方式复制文件,但出现与访问有关的错误 错误:EPERM:不允许操作,stat '\machines old'

期望它拾取文件并复制到服务器目标文件夹

azure-pipelines on-premises-instances azure-agent
1个回答
0
投票

您可以提交 PowerShell 脚本文件并将其推送到 Azure DevOps 私有项目中的 git 存储库。并为此存储库设置 CI 管道,如下所示。

# azure-pipelines.yml

trigger:
  batch: true
  branches:
    include:
    - main

stages:
- stage: A
  jobs:
  - job: A1
    pool:
     name: {pool_name}  # The name of agent pool where the self-hosted (on prem) agent is in.
     demands: Agent.Name -equals {agent_name}  # Can use the demands to specify the particular self-hosted agent by the agent name.
    steps:
    - task: CopyFiles@2
      displayName: 'Copy .ps1 files'
      inputs:
        SourceFolder: '$(Build.SourcesDirectory)'
        Contents: '**/*.ps1'
        TargetFolder: '\\server\DevOps'
        OverWrite: true

描述:

  1. 确保

    azure-pipelines.yml
    文件位于 Azure DevOps 中 git 存储库的
    main
    分支中。

  2. 在安装自托管代理的代理计算机上,确保您具有直接访问远程文件共享“

    \\server\DevOps
    ”的权限。建议将文件共享映射为代理计算机上的网络驱动器(例如,驱动器Z:),以便您可以像访问代理计算机上的本地驱动器一样轻松访问它。

  3. 在代理计算机上安装/配置自托管代理时,请确保您提供了用于登录计算机的帐户的用户名和密码。不要使用默认的“

    NT AUTHORITY\NETWORK SERVICE
    ”(Windows)。通过这种方式,代理将使用您提供的帐户登录计算机并在计算机上运行任务,并且还可以访问文件共享(或映射的网络驱动器)。

  4. 使用上述配置,当提交新更改并将其推送到 Azure DevOps 中 git 存储库的

    main
    分支时,将触发管道。然后,CopyFiles@2 任务将在作业中运行,将
    .ps1
    文件复制到文件共享“
    \\server\DevOps
    ”中。

© www.soinside.com 2019 - 2024. All rights reserved.