azure 是否可以将构建工件从pipeline复制到repo

vwkv1x7d  于 2023-03-13  发布在  其他
关注(0)|答案(2)|浏览(197)

我试图复制我发布的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.

免责声明:这通常不是一个好主意,在大多数情况下,从工件提要中获取工件要好得多!

5cg8jx4n

5cg8jx4n1#

您可以下载工件并使用命令行任务中的git命令将其推送到repo,请参考下面的示例,它对我很有效。

# '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
...

ie3xauqp

ie3xauqp2#

另一种方法是推送到repo,然后从远程git/同步-基本上是一种自动拉文件的方式。

相关问题