【发布时间】:2022-10-23 22:54:13
【问题描述】:
我在 Windows 服务器上有一个自托管的 Github Action 运行器,我的目标是从 Jenkins 迁移到 GitHub 的工作流程。由于某种原因,我很难理解如何使用环境变量。
我的自托管服务器上有一个文件夹,我想在其中放置一些通用构建脚本,这些脚本是在 Powershell 中创建的。
所以我的main.yml 看起来像这样
# 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
我已经尝试了各种变体来获取环境变量BUILD_SCRIPTS_PATH。
.\${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
我不断收到此错误
+ ${BUILD_SCRIPTS_PATH}\Powershell\meta.ps1 -MetaFilePath ProjectMe ...
+ ~~~~~~~~~~~~~~~~~~~~
Unexpected token '\Powershell\meta.ps1' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
SET 命令输出的一小部分
Run SET
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Administrator\AppData\Roaming
BUILD_SCRIPTS_PATH=E:\github\BuildScripts
ChocolateyInstall=C:\ProgramData\chocolatey
我已经查看了来自 GitHub GitHub Documentation 的文档,但我真的不明白我做错了什么。我真的很感激有人可以向我解释我做错了什么。
【问题讨论】:
标签: github workflow github-actions-self-hosted-runners