Run common task in github action or alternative of before_script in github workflow ci

Hello all,

I’m trying to shift my CI workflow from GitLab to Github So just having some queries:

  • In Gitlab CI, if there are common steps running for each job we use to place it in
    Like:
gitlab-ci.yml

  before_script:
    - export GOPATH=$HOME/go
    - export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
    - pwd
    - echo "Starting Tests"

before_script automatically runs before the execution of every step in a job.
So, Is there a way to achieve this using Github Actions?

Example:

jobs:
  tests:
    runs-on: ubuntu-latest
    steps:
      - name: Running for app1
        run: |
          echo "common command 1"
          echo "common command 2"
          echo "Hello world"
          
      - name: Running for app2
        run: |
          echo "common command 1"
          echo "common command 2"
          echo "Hello all"

Can we place all common commands in a job that is like before_Script or something like that?

@uditgaurav,
Currently, GitHub Actions does not support the feature likes before_script in Gitlab CI.

Can we place all common commands in a job that is like before_Script or something like that?

I think this is not work. if you are using GitHub-hosted runners in to run the job in your workflow, each job in the workflow executes in a fresh instance of the virtual machine. So, the system configurations (such as environment variables) you set in a job generally are not applicable to other jobs.
And GitHub Actions also does not support the feature likes Template (such as job templates and step templates) for YAML Pipelines on Azure Pipelines .

If your projects really need the similar features, I recommend you directly report a feature request here. That will allow you to directly interact with the appropriate engineering team, and make it more convenient for the engineering team to collect and categorize your suggestions.

2 Likes