我對作業流 GitHub Action 有疑問。Secrets 環境是 GitHub 發明的最難也是最令人費解的東西。我正在使用以下代碼,我意識到我無法將環境機密檢索為環境變數。
deploy-snowflake-changes-dev:
name: deploy schemas changes to dev
needs: ShitTest
if: needs.ShitTest.outputs.output == 'true'
environment:
name: ${{inputs.devEnv}}
runs-on: ubuntu-latest
env:
SF_ACCOUNT: ${{ secrets.SF_ACCOUNT }}
SF_USERNAME: ${{ secrets.SF_USERNAME }}
SF_ROLE: ${{ secrets.SF_ROLE }}
SF_WAREHOUSE: ${{ secrets.SF_WAREHOUSE }}
SF_DATABASE: ${{ secrets.SF_DATABASE }}
SNOWFLAKE_PASSWORD: ${{ secrets.SF_PASSWORD }}
SF_SCHEMA: ${{secrets.SF_SCHEMA}}
SF_HISTORY_TABLE: ${{secrets.SF_HISTORY_TABLE}}
當我嘗試在后面的代碼中使用以前的環境變數時,它不起作用,就像秘密不存在但它們存在一樣。所有這些秘密都存盤為${{inputs.devEnv}}環境秘密。
我的問題是:會發生什么?如何使它作業?我沒有解決方案。
完整的代碼和我有另一個作業流程,我在下面的作業流程中呼叫 tje 及其引數。
這是整個作業流程的實作:
name: snowflake Devops
on:
workflow_call:
inputs:
Organization:
required: true
type: string
Repository:
required: true
type: string
devEnv:
required: true
type: string
uatEnv:
required: true
type: string
prodEnv:
required: true
type: string
devBranch:
required: true
type: string
uatBranch:
required: true
type: string
prodBranch:
required: true
type: string
rootFolder:
required: true
type: string
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
ShitTest:
name: This is a shit test to get around the if condition
runs-on: ubuntu-latest
outputs:
output: ${{ steps.condition.outputs.test }}
steps:
- name: shit test
id: condition
shell: pwsh
run: |
$branch = '${{ github.ref }}'
$event = '${{ github.event_name }}'
if($branch -eq 'refs/heads/${{ inputs.uatBranch }}' -AND $event -eq 'push' ) {
$isTrigger = $true
echo "::set-output name=test::$isTrigger"
Write-Host "Deployment will be triggered" -ForegroundColor Cyan
}else {
$isTrigger = $false
echo "::set-output name=test::$isTrigger"
Write-Host "Deployment will not be triggered" -ForegroundColor Cyan
}
deploy-snowflake-changes-dev:
name: deploy schamas changes to dev
needs: ShitTest
if: needs.ShitTest.outputs.output == 'true'
environment:
name: ${{inputs.devEnv}}
runs-on: ubuntu-latest
env:
SF_ACCOUNT: ${{ secrets.SF_ACCOUNT }}
SF_USERNAME: ${{ secrets.SF_USERNAME }}
SF_ROLE: ${{ secrets.SF_ROLE }}
SF_WAREHOUSE: ${{ secrets.SF_WAREHOUSE }}
SF_DATABASE: ${{ secrets.SF_DATABASE }}
SNOWFLAKE_PASSWORD: ${{ secrets.SF_PASSWORD }}
SF_SCHEMA: ${{secrets.SF_SCHEMA}}
SF_HISTORY_TABLE: ${{secrets.SF_HISTORY_TABLE}}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Use Python 3.8.x
uses: actions/[email protected]
with:
python-version: 3.8.x
- name: Run schemachange
shell: pwsh
run: |
echo "SF_ACCOUT"
echo "${{env.SF_ACCOUNT}}"
echo "GITHUB_WORKSPACE: $GITHUB_WORKSPACE"
python --version
echo "Step 1: Installing schemachange"
pip install schemachange
echo "Step 2: Getting variables"
$schemachangeconfigPath = "./configurations/${{inputs.devBranch}}/schemachange-config.json"
$variables = Get-Content $schemachangeconfigPath | Out-String | ConvertFrom-Json
## Need something like that in input of schemachange cmdline deploy : '{\"database\":\"DB_DEMO_PPROD\", \"schema\":\"DEMO\", \"table\":\"DEMO_TABLE\"}'
$count=0
$varsString = "{"
foreach ($p in $variables.psobject.Properties) {
$count =1
$name = $p.name
$value = $p.value
if($count -ne $variables.psobject.Properties.name.Length) {
$varsString = [System.String]::Concat($varsString,"\","`"$name","\","`"",":","\","`"$value","\","`"",",")
}else {
$varsString = [System.String]::Concat($varsString,"\","`"$name","\","`"",":","\","`"$value","\","`"","}")
}
}
echo "Step 3: Running schemachange"
schemachange deploy -f ./${{inputs.rootFolder}} -a ${{env.SF_ACCOUNT}} -u ${{env.SF_USERNAME}} -r ${{env.SF_ROLE}} -w ${{env.SF_WAREHOUSE}} -d ${{env.SF_DATABASE}} -c ${{env.SF_DATABASE}}.${{env.SF_SCHEMA}}.${{env.SF_HISTORY_TABLE}} --vars $varsString --create-change-history-table -v
感謝您的任何幫助。
uj5u.com熱心網友回復:
我終于找到了讓它作業的方法。有必要secrets在呼叫者作業流和被呼叫作業流中添加一個部分,如下所示:
- 被呼叫作業流示例
secrets:
TOKEN:
required: true
SF_DATABASE:
required: true
SF_SCHEMA:
required: true
SF_HISTORY_TABLE:
required: true
- 呼叫者作業流程示例:
secrets:
TOKEN: ${{ secrets.TOKEN }}
SF_DATABASE: ${{ secrets.SF_DATABASE }}
SF_SCHEMA: ${{secrets.SF_SCHEMA}}
SF_HISTORY_TABLE: ${{secrets.SF_HISTORY_TABLE}}
然后,被呼叫作業流中的秘密可以如下使用:${{ secrets.SF_DATABASE }}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/516593.html
