Reputation: 294
So i am trying to execute a powershell script from my .gitlab-ci.yaml where i want to have one of the script variables based on an environment variable as a starting point for my powershell script.
i have a .gitlab-ci.yaml which includes the following:
job1:
stage: ps
script:
- powershell -File .\psfile.ps1 -var1 lalalal -var2 Solution -var3 '%CI_PROJECT_DIR%'
when posting the CI_PROJECT_DIR ev from powershell with write-output (or similar) i am getting an empty string.
when i do the common echo '%CI_PROJECT_DIR%' i am getting the correct path
Upvotes: 4
Views: 6226
Reputation: 440337
Without knowing the specifics of GitLab .gitlab-ci.yaml
files, my guess is that by default it is the host platform's default shell that is used to execute commands.
Given that on Windows cmd.exe
is the default shell, you must use its syntax, which implies:
You need to use %...%
to enclose environment-variable references (which you already do)
In order to quote a value, you must use "..."
(double quotes); by contrast, '...'
(single quotes) have no syntactic function in cmd.exe
and are passed as part of the argument.
Therefore, try with the following line instead:
- powershell -File .\psfile.ps1 -var1 lalalal -var2 Solution -var3 "%CI_PROJECT_DIR%"
Upvotes: 2
Reputation: 969
Use $env:CI_PROJECT_DIR
(and remove the single quotes around it in your example because single quotes are literal string constants). This is how environment variables are addressed in PowerShell, the syntax is different to cmd.exe. See also the GitLab documentation here.
If you you want it more detailed in terms of scoping, then you can also call the .net methods [System.Environment]::GetEnvironmentVariable(...)
Upvotes: 0