Hello everyone,
I'm encountering an issue with a Bitbucket pipeline running on a self-hosted Windows runner. I’m trying to use environment variables to execute nuget.exe
via PowerShell, but I’m getting an error related to Invoke-Expression
.
Invoke-Expression : The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object. At C:\atlassian-bitbucket-pipelines-runner\temp\...\tmp\powershellScript.ps1:11 char:50 + '& $env:NUGET_PATH restore $env:SOLUTION_PATH' | Invoke-Expression + ~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Invoke-Expression], RuntimeException + FullyQualifiedErrorId : BadExpression,Microsoft.PowerShell.Commands.InvokeExpressionCommand
Below is my YAML script:
pipelines:
variables:
NUGET_PATH: 'C:\Nuget\nuget.exe'
MSBUILD_PATH: 'some path'
MAIN_PROJECT_PATH:'some path'
SOLUTION_PATH : 'some path'
branches:
branch1:
- step:
name: Building the branch1
runs-on:
- self.hosted
- windows
script:
- "& $env:NUGET_PATH restore $env:SOLUTION_PATH"
I’ve tried different variations, including using backticks and escaping, but I’m still facing the same error. Has anyone encountered this issue or know how to correctly use environment variables in this context? (My syntax in yaml file is coorect when i paste in the question bar so it is not properly formatted)
Any help would be greatly appreciated!
Hello @Yogesh Kumar ,
and welcome to the Community!
Checking the YAML file you shared, I can think of two issues that are causing the error :
script:
- |
& "$env:MyCommand" -v
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.