Search code examples
variablesyamlgithub-actions

Github Action - use Variable in the script


With Github Actions how to do a backup of a file?

I need to create a new folder named with the date/time of today.

name: Backup Database

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Backup
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.HOST }}
          username: ${{ secrets.USERNAME }}
          key: ${{ secrets.KEY }}
          port: 22
          script: |
            DATE=${{ NEW DATE }} # Need to create a variable with date/time
            mkdir backup_${{ DATE }} # Create a new folder with the date/time

Solution

  • This user found a hack to create vars that are generated with bash commands output.

    In his words:

    I found a way to hack this limitation. Write your VAR on disk (the CI system disk), then cat $my_var to use your VAR in every step you need

    Reference: "How to define env variable?"