0

I have a self hosted Github Action runner on a Windows server, my goal is to migrate from Jenkins to GitHub's workflow. I have a very hard to time understand how to use the environment variables for some reason.

I have a folder on my self hosted server, where I want to place some generic build scripts, which is created in Powershell.

So my main.yml look like this

# This is a basic workflow to help you get started with Actions

name: Build integration

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "develop" branch
  push:
    branches: ["*"]
  pull_request:
    branches: ["*"]
    

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  continuous-integration:
    # The type of runner that the job will run on
    runs-on: [self-hosted, .net]

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it      
      - name: Checkout code
        uses: actions/checkout@v3     

      # get environment
      - name: Get system environments
        uses: FranzDiebold/github-env-vars-action@v2 

      # show environment
      - name: Show all enronment variables
        run: SET
        shell: cmd
        
      # read meta file
      - name: read project meta file
        run: |
          .\$BUILD_SCRIPTS_PATH}\Powershell\meta.ps1 -MetaFilePath ProjectMeta.json
        shell: powershell       

I have tried all kinds of variants to get the environment variable BUILD_SCRIPTS_PATH out.

.\${env.BUILD_SCRIPTS_PATH}\Powershell\meta.ps1 -MetaFilePath ProjectMeta.json
.\${{BUILD_SCRIPTS_PATH}}\Powershell\meta.ps1 -MetaFilePath ProjectMeta.json
.\$env.BUILD_SCRIPTS_PATH\Powershell\meta.ps1 -MetaFilePath ProjectMeta.json
.\$BUILD_SCRIPTS_PATH\Powershell\meta.ps1 -MetaFilePath ProjectMeta.json

I keep getting this error

+ ${BUILD_SCRIPTS_PATH}\Powershell\meta.ps1 -MetaFilePath ProjectMe ...
+                          ~~~~~~~~~~~~~~~~~~~~
Unexpected token '\Powershell\meta.ps1' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

a minor part of the output from the SET command

Run SET
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Administrator\AppData\Roaming
BUILD_SCRIPTS_PATH=E:\github\BuildScripts
ChocolateyInstall=C:\ProgramData\chocolatey

I have looked into the documentation from GitHub GitHub Documentation but I don't really understand what i am doing wrong. I would really appreciate is someone could explain to me what i am doing wrong.

aSemy
  • 5,485
  • 2
  • 25
  • 51
Rene Sørensen
  • 99
  • 1
  • 1
  • 8

1 Answers1

0

You can read more about using environment variables in GitHub actions here.

From what you've posted it doesn't seem like you're providing the BUILD_SCRIPTS_PATH to the workflow's environment.

You can add it like this:

# read meta file
    - name: read project meta file
      run: |
        .\$BUILD_SCRIPTS_PATH\Powershell\meta.ps1 -MetaFilePath ProjectMeta.json
      shell: powershell   
      env:
         BUILD_SCRIPTS_PATH: ${{ secrets:build_scripts_path}}

Then just make sure to add the build_scripts_path as a GitHub secret.

Code on the Rocks
  • 11,488
  • 3
  • 53
  • 61