azure - 是否可以将构建工件从管道复制到存储库中

标签 azure azure-devops build

免责声明:这通常不是一个好主意,最好使用 Azure Artifacts !

我正在尝试将我发布的 zip 版本复制到我的 azure 存储库中以便于访问。我有以下 YML 代码。请参阅我的问题的内嵌评论:

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(build.artifactstagingdirectory)\MyFolder'
    includeRootFolder: true
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)\zipfolder/$(Build.BuildId).zip'
    replaceExistingArchive: true

- task: PublishBuildArtifacts@1    
  displayName: 'Publish Artifact: drop'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)\zipfolder'
    TargetPath: '$(Build.SourcesDirectory)\MyFolder' // Here I would expect the code to copy the zip into my repo.

最佳答案

您可以下载该工件并在命令行任务中使用 git 命令将其推送到存储库,引用下面的示例,它对我有用。

# 'Allow scripts to access the OAuth token' was selected in pipeline.  Add the following YAML to any steps requiring access:
#       env:
#           MY_ACCESS_TOKEN: $(System.AccessToken)
# Variable Group 'vargroup1' was defined in the Variables tab
resources:
  repositories:
  - repository: self
    type: git
    ref: refs/heads/testb2
jobs:
- job: Job_1
  displayName: Agent job 1
  pool:
    vmImage: ubuntu-20.04
  steps:
  - checkout: self
    persistCredentials: True
  - task: ArchiveFiles@2
    displayName: Archive README.md
    inputs:
      rootFolderOrFile: README.md
      archiveFile: $(Build.ArtifactStagingDirectory)\zipfolder/$(Build.BuildId).zip
  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: drop'
    inputs:
      PathtoPublish: $(Build.ArtifactStagingDirectory)\zipfolder
  - task: DownloadBuildArtifacts@1
    displayName: Download Build Artifacts
    inputs:
      artifactName: drop
  - task: CmdLine@2
    displayName: Command Line Script
    inputs:
      script: >-
        cd $(System.ArtifactsDirectory)\zipfolder

        git config --global user.email "xxxxx"

        git config --global user.name "xxxxx"

        git init

        git add .

        git commit -m "123"

        git remote add origin https://$(System.AccessToken)@dev.azure.com/orgname/testpro1/_git/testpro4

        git push https://$(System.AccessToken)@dev.azure.com/orgname/testpro1/_git/testpro4
...

enter image description here

enter image description here

关于azure - 是否可以将构建工件从管道复制到存储库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69270012/

相关文章:

java - 动态 Web 项目创建中的 Eclipse 构建问题

azure - 如何终止特定的 Azure 辅助角色实例

azure-devops - PublishPipelineArtifact 已弃用 - 将本地目录或文件发布为当前管道的命名工件

Azure DevOps - 小部件大小

azure 指定任务输出的放置位置

Windows 中不存在 OpenCV 库文件 (imgproc.hpp)

build - 在 travis-ci -golang 上找不到包

visual-studio - 使用 WebJob 将 Web 应用程序发布到 Azure 时卡住

database - 为基于日期的全局 DocumentDB 应用程序选择正确的 PartitionKey

Azure APIM 作为纯代理