我正在创建一个使用 github 操作复制 blob 的管道,我遇到的问题是无法检索代码中的秘密或变量,工作流程不断失败,因为它无法读取源、目标或密钥。我不知道我在这里缺少什么是我的代码
name: Azure Blob AZCopy Workflow secrets
on:
workflow_dispatch:
inputs:
environment:
description: 'Select the environment (e.g., prod2qa)'
required: true
jobs:
copy_blob_container:
runs-on: ubuntu-latest
env:
SOURCE_SAS_TOKEN: ${{ secrets.SOURCE_SAS_TOKEN }}
DEST_SAS_TOKEN: ${{ secrets.DEST_SAS_TOKEN }}
SOURCE_ACCOUNT_NAME: ${{ secrets.SOURCE_ACCOUNT_NAME }}
DEST_ACCOUNT_NAME: ${{ secrets.DEST_ACCOUNT_NAME }}
SOURCE_CONTAINER: ${{ secrets.SOURCE_CONTAINER }}
DEST_CONTAINER: ${{ secrets.DEST_CONTAINER }}
steps:
- name: Validate required parameters
run: |
[ -n "$SOURCE_SAS_TOKEN" ] || (echo "SOURCE_SAS_TOKEN is missing" && exit 1)
[ -n "$DEST_SAS_TOKEN" ] || (echo "DEST_SAS_TOKEN is missing" && exit 1)
[ -n "$SOURCE_ACCOUNT_NAME" ] || (echo "SOURCE_ACCOUNT_NAME is missing" && exit 1)
[ -n "$DEST_ACCOUNT_NAME" ] || (echo "DEST_ACCOUNT_NAME is missing" && exit 1)
[ -n "$SOURCE_CONTAINER" ] || (echo "SOURCE_CONTAINER is missing" && exit 1)
[ -n "$DEST_CONTAINER" ] || (echo "DEST_CONTAINER is missing" && exit 1)
- name: Setup azcopy
run: |
wget -O azcopy_v10.tar.gz https://aka.ms/downloadazcopy-v10-linux && tar -xf azcopy_v10.tar.gz --strip-components=1 && sudo mv azcopy /usr/local/bin/
- name: Construct URLs
run: |
echo "SOURCE_URL=https://$SOURCE_ACCOUNT_NAME.blob.core.windows.net/$SOURCE_CONTAINER?$SOURCE_SAS_TOKEN" >> $GITHUB_ENV
echo "DEST_URL=https://$DEST_ACCOUNT_NAME.blob.core.windows.net/$DEST_CONTAINER?$DEST_SAS_TOKEN" >> $GITHUB_ENV
- name: Debug (Print command structure without secrets)
run: |
echo "azcopy copy \$SOURCE_URL \$DEST_URL --recursive"
- name: Secret Structure Debugging
run: |
echo "SOURCE_SAS_TOKEN Length = " ${#SOURCE_SAS_TOKEN}
echo "DEST_SAS_TOKEN Length = " ${#DEST_SAS_TOKEN}
- name: Copy Blob Containers
run: |
azcopy copy "$SOURCE_URL" "$DEST_URL" --recursive
尝试使用 {{ env.SOURCE_SAS_TOKEN }} 访问