Home > Net >  How to use github-secret in github action workflow?
How to use github-secret in github action workflow?

Time:04-05

so I have this code:

name: run-script
on: push

jobs:
  run_tests:
    runs-on: ubuntu-20.04
    steps:
    - uses: actions/checkout@v2
    - name: Run script file
      run: |
         echo {here should be the secret} > ~/id_rsa
 
      shell: bash

On my git action, where {here should be the secret} I want to put the variable, which is a secret token saved as a repo secret. How can this be done?

Thank you for your help.

CodePudding user response:

Assuming you have a secret named TOKEN, you can use it like so:

name: run-script
on: push

jobs:
  run_tests:
    runs-on: ubuntu-20.04
    steps:
    - uses: actions/checkout@v3
    - name: Run script file
      run: |
         echo ${{ secrets.TOKEN }} > ~/id_rsa
 
      shell: bash

Unrelated to how to use secrets, please note that > will override the contents of ~/id_rsa.

Secondly, if you want to do something with your private key (which is my guess based on the filename), the correct file would be in ~/.ssh/id_rsa.

And lastly, note that I have changed the checkout action to v3 as that's the latest available version.

CodePudding user response:

In the repository settings go to Secrets -> Actions -> New repository secret. You can view more details in the documentation.

  • Related