使用 github 操作将特定文件扩展名推送到 azure 存储帐户

时间:2021-01-05 12:00:14

标签: github github-actions

我第一次使用 github action。 我需要实现的是,当推送包含不同文件的项目(例如: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 ./<folder name>/*.txt 但我收到一个错误:

 ValidationError: incorrect usage: source must be an existing directory

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

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

1 个答案:

答案 0 :(得分: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"
相关问题