【问题标题】:Use github action to push specific file extentions to azure storage account使用 github 操作将特定文件扩展名推送到 azure 存储帐户
【发布时间】:2021-01-05 12:00:14
【问题描述】:

我是第一次使用 github 操作。 我需要实现的是,当推送一个包含不同文件的项目(例如:json 文件和 txt 文件)时,我希望 github 操作仅将文件 .txt 推送到 azure 存储帐户。

现在,我的 github 管道结构如下,并且可以正常工作:

on: [push]

env:
  AZURE_RESOURCE_GROUP: <resource-group-name>
  BLOB_STORAGE_ACCOUNT_NAME: <storage-account-name>
# name: AzureARMDeploy

jobs:

    modules:
      runs-on: ubuntu-latest
      steps:

      - name: Login to Azure
        uses: azure/login@v1
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}

      - name: Checkout source code
        uses: actions/checkout@v2

      - name: Deploy to storage using CLI
        uses: azure/CLI@v1
        with:
          azcliversion: latest
          inlineScript: |
            ls
            # show azure account being used
            az account show
            # az storage account upload
            az storage blob upload-batch --account-name ${{ env.BLOB_STORAGE_ACCOUNT_NAME }} -d '<storagename>' -s <folder>
            az storage blob upload-batch --account-name ${{ env.BLOB_STORAGE_ACCOUNT_NAME }} -d '<storagename>' -s ./<folder name>/<file extentions>

在第一个upload-batch 中,我可以将所有内容文件夹复制到我的 azure 存储帐户。

在最后一批上传中:

az storage blob upload-batch --account-name ${{ env.BLOB_STORAGE_ACCOUNT_NAME }} -d '<storagename>' -s ./<folder name>/<file extentions>

我尝试过: -s ./&lt;folder name&gt;/*.txt 但我得到一个错误:

 ValidationError: incorrect usage: source must be an existing directory

我很确定错误是由*.txt 引起的,我想知道你们中是否有人知道如何实现这个逻辑的任何解决方案。

非常感谢您的宝贵时间和帮助。

【问题讨论】:

    标签: github github-actions


    【解决方案1】:

    你可以使用--pattern标志

    --pattern
    
    The pattern used for globbing files or blobs in the source. The supported patterns are '*', '?', '[seq]', and '[!seq]'. For more information, please refer to https://docs.python.org/3.7/library/fnmatch.html.
    
    

    应该是这样的

    az storage blob upload-batch --account-name ${{ env.BLOB_STORAGE_ACCOUNT_NAME }} -d '<storagename>' -s './<folder name>' --pattern "*.txt"
    

    【讨论】:

    • 成功了。非常感谢你,伙计。你是个传奇
    • @NaydenVan 如果我的回复对您有帮助,您可以考虑点赞吗?
    • 对不起,有什么办法可以只将来自不同子目录的 json 文件推送到存储中?我一直有一个错误,我找不到解决它的方法
    猜你喜欢
    • 1970-01-01
    • 2023-01-02
    • 2020-10-19
    • 2021-10-21
    • 2021-01-01
    • 2020-11-17
    • 2014-07-12
    • 2020-02-17
    • 2021-05-11
    相关资源
    最近更新 更多