using variable and secrets in gitub calling workflow
Accessing variables
If you defined your variables via Github-> Settings-> Secret and Variable -> Variable, then you can reference it using ${{ vars.my_variable }}. Pretty straight forward.
Accessing secrets
Accessing secret is abit tricky for calling workflow. You need to declare the secrets to be used, like what is shown below
1. add secrets before calling the workflow
build-image:
uses: mitzen/dotnet-gaction/.github/workflows/buildimage.yaml@main
needs: build-project
with:
artifact: build-artifact
repository: kepung
tags: "dotnetaction"
secrets:
docker_username: ${{ secrets.DOCKERUSER}}
docker_token: ${{ secrets.DOCKERUSER}}
2. Next, add the secret as parameter in the calling workflow and use it
on:
workflow_call:
secrets:
docker_username:
required: true
docker_token:
required: true
inputs:
artifact:
required: true
type: string
repository:
required: true
type: string
tags:
required: true
type: string
jobs:
build-docker-image:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
- name: run script
run: |
echo ${{ secrets.docker_username}}
You will noticed we still reference it as secrets.docker_username.
Please checkout limitation of the workflow too
https://docs.github.com/en/actions/using-workflows/reusing-workflows#limitations
Comments