Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: PowerShell@2 is generating a parser error #20865

Open
4 of 7 tasks
jachin84 opened this issue Feb 20, 2025 · 0 comments
Open
4 of 7 tasks

[BUG]: PowerShell@2 is generating a parser error #20865

jachin84 opened this issue Feb 20, 2025 · 0 comments
Labels
Area: ABTT Akvelon Build Tasks Team area of work bug triage

Comments

@jachin84
Copy link

New issue checklist

Task name

PowerShell@2

Task version

2.247.1

Issue Description

I am using the PowerShell@2 task to execute a script with arguments as shown below.

- task: PowerShell@2
  inputs:
    pwsh: true
    targetType: filePath
    filePath: $(Build.SourcesDirectory)/script.ps1
    arguments: >
       -DeploymentLogPath $(Build.ArtifactStagingDirectory)/Logs
      -Tag $(SEMVER)
      -Verbose;

The task always fails with:

ParserError: /ado/_work/_temp/5746ce19-436f-4ddd-bfa1-f3344e169c1e.ps1:7
Line |
##[debug]$LASTEXITCODE: {0}' -f $LASTEXITCOD …
     |                                    ~~~~~~~~~~~~~~
     | Variable reference is not valid. ':' was not followed by a valid
     | variable name character. Consider using ${} to delimit the name.

The generated script in the temp folder is:

$ErrorActionPreference = 'stop'
$ProgressPreference = 'silentlyContinue'
. '/ado/_work/2/s/script.ps1' -DeploymentLogPath /ado/_work/2/a/Logs" -Tag 1.964.34287-main -Verbose;
if (!(Test-Path -LiteralPath variable:LASTEXITCODE)) {
    Write-Host '##vso[task.debug]$LASTEXITCODE is not set.'
} else {
    Write-Host ('##vso[task.debug]$LASTEXITCODE: {0}' -f $LASTEXITCODE)
    exit $LASTEXITCODE
}

You need to escape $LASTEXITCODE eg.

if (!(Test-Path -LiteralPath variable:LASTEXITCODE)) {
    Write-Host '##vso[task.debug]`$LASTEXITCODE is not set.' #NOTE : see the backtick before $
} else {
    Write-Host ('##vso[task.debug]`$LASTEXITCODE: {0}' -f $LASTEXITCODE)
    exit $LASTEXITCODE
}

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

n/a

Operation system

Ubuntu 22.04.5 LTS

Relevant log output

##[debug]/usr/bin/pwsh arg: . '/ado/_work/_temp/5746ce19-436f-4ddd-bfa1-f3344e169c1e.ps1'
2025-02-20T04:55:36.3422666Z ##[debug]exec tool: /usr/bin/pwsh
2025-02-20T04:55:36.3422794Z ##[debug]arguments:
2025-02-20T04:55:36.3422909Z ##[debug]   -NoLogo
2025-02-20T04:55:36.3423026Z ##[debug]   -NoProfile
2025-02-20T04:55:36.3423147Z ##[debug]   -NonInteractive
2025-02-20T04:55:36.3423259Z ##[debug]   -Command
2025-02-20T04:55:36.3423391Z ##[debug]   . '/ado/_work/_temp/5746ce19-436f-4ddd-bfa1-f3344e169c1e.ps1'
2025-02-20T04:55:36.3423516Z [command]/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command . '/ado/_work/_temp/5746ce19-436f-4ddd-bfa1-f3344e169c1e.ps1'
2025-02-20T04:55:36.5551031Z �[31;1mParserError: �[0m/ado/_work/_temp/5746ce19-436f-4ddd-bfa1-f3344e169c1e.ps1:7�[0m
2025-02-20T04:55:36.5551386Z �[31;1m�[0m�[36;1mLine |�[0m
2025-02-20T04:55:36.5551846Z ##[debug]�[36;1m$LASTEXITCODE:�[0m {0}' -f $LASTEXITCOD …�[0m
2025-02-20T04:55:36.5552067Z �[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m     | �[31;1m                                   ~~~~~~~~~~~~~~�[0m
2025-02-20T04:55:36.5552256Z �[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m     | �[31;1mVariable reference is not valid. ':' was not followed by a valid�[0m
2025-02-20T04:55:36.5552456Z �[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m�[31;1m�[36;1m     | �[31;1mvariable name character. Consider using ${} to delimit the name.�[0m
2025-02-20T04:55:36.5664793Z 
2025-02-20T04:55:36.5666859Z ##[debug]Exit code 1 received from tool '/usr/bin/pwsh'
2025-02-20T04:55:36.5669029Z ##[debug]STDIO streams have closed for tool '/usr/bin/pwsh'
2025-02-20T04:55:36.5673436Z ##[debug]task result: Failed
2025-02-20T04:55:36.5685235Z ##[error]PowerShell exited with code '1'.

Full task logs with system.debug enabled

 2025-02-20T04:55:36.2443572Z ##[debug]Evaluating condition for step: 'PowerShell'
2025-02-20T04:55:36.2444196Z ##[debug]Evaluating: SucceededNode()
2025-02-20T04:55:36.2444335Z ##[debug]Evaluating SucceededNode:
2025-02-20T04:55:36.2444574Z ##[debug]=> True
2025-02-20T04:55:36.2444709Z ##[debug]Result: True
2025-02-20T04:55:36.2444870Z ##[section]Starting: PowerShell
2025-02-20T04:55:36.2448841Z ==============================================================================
2025-02-20T04:55:36.2448924Z Task         : PowerShell
2025-02-20T04:55:36.2448951Z Description  : Run a PowerShell script on Linux, macOS, or Windows
2025-02-20T04:55:36.2448989Z Version      : 2.247.1
2025-02-20T04:55:36.2449019Z Author       : Microsoft Corporation
2025-02-20T04:55:36.2449066Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
2025-02-20T04:55:36.2449107Z ==============================================================================
2025-02-20T04:55:36.2906143Z ##[debug]Using node path: /ado/externals/node20_1/bin/node
2025-02-20T04:55:36.3184019Z ##[debug]system.debug=True
2025-02-20T04:55:36.3184493Z ##[debug]DistributedTask.Tasks.Node.SkipDebugLogsWhenDebugModeOff=True
2025-02-20T04:55:36.3217405Z ##[debug]agent.TempDirectory=/ado/_work/_temp
2025-02-20T04:55:36.3219665Z ##[debug]loading inputs and endpoints
2025-02-20T04:55:36.3220390Z ##[debug]loading INPUT_TARGETTYPE
2025-02-20T04:55:36.3230572Z ##[debug]loading INPUT_FILEPATH
2025-02-20T04:55:36.3231151Z ##[debug]loading INPUT_ARGUMENTS
2025-02-20T04:55:36.3231288Z ##[debug]loading INPUT_SCRIPT
2025-02-20T04:55:36.3231425Z ##[debug]loading INPUT_ERRORACTIONPREFERENCE
2025-02-20T04:55:36.3231566Z ##[debug]loading INPUT_WARNINGPREFERENCE
2025-02-20T04:55:36.3231700Z ##[debug]loading INPUT_INFORMATIONPREFERENCE
2025-02-20T04:55:36.3232134Z ##[debug]loading INPUT_VERBOSEPREFERENCE
2025-02-20T04:55:36.3234154Z ##[debug]loading INPUT_DEBUGPREFERENCE
2025-02-20T04:55:36.3234732Z ##[debug]loading INPUT_PROGRESSPREFERENCE
2025-02-20T04:55:36.3235373Z ##[debug]loading INPUT_FAILONSTDERR
2025-02-20T04:55:36.3237494Z ##[debug]loading INPUT_SHOWWARNINGS
2025-02-20T04:55:36.3237681Z ##[debug]loading INPUT_IGNORELASTEXITCODE
2025-02-20T04:55:36.3238345Z ##[debug]loading INPUT_PWSH
2025-02-20T04:55:36.3240761Z ##[debug]loading INPUT_WORKINGDIRECTORY
2025-02-20T04:55:36.3240954Z ##[debug]loading INPUT_RUNSCRIPTINSEPARATESCOPE
2025-02-20T04:55:36.3241101Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2025-02-20T04:55:36.3241254Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2025-02-20T04:55:36.3241877Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2025-02-20T04:55:36.3247212Z ##[debug]loading SECRET_SYSTEM_ACCESSTOKEN
2025-02-20T04:55:36.3247704Z ##[debug]loaded 20
2025-02-20T04:55:36.3249673Z ##[debug]Agent.ProxyUrl=undefined
2025-02-20T04:55:36.3249877Z ##[debug]Agent.CAInfo=undefined
2025-02-20T04:55:36.3250055Z ##[debug]Agent.ClientCert=undefined
2025-02-20T04:55:36.3250192Z ##[debug]Agent.SkipCertValidation=undefined
2025-02-20T04:55:36.3259365Z ##[debug]check path : /ado/_work/_tasks/PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1/2.247.1/task.json
2025-02-20T04:55:36.3259889Z ##[debug]adding resource file: /ado/_work/_tasks/PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1/2.247.1/task.json
2025-02-20T04:55:36.3260054Z ##[debug]system.culture=en-US
2025-02-20T04:55:36.3266424Z ##[debug]errorActionPreference=stop
2025-02-20T04:55:36.3266968Z ##[debug]warningPreference=default
2025-02-20T04:55:36.3267114Z ##[debug]informationPreference=default
2025-02-20T04:55:36.3267251Z ##[debug]verbosePreference=default
2025-02-20T04:55:36.3267384Z ##[debug]debugPreference=default
2025-02-20T04:55:36.3267557Z ##[debug]progressPreference=silentlyContinue
2025-02-20T04:55:36.3267718Z ##[debug]showWarnings=false
2025-02-20T04:55:36.3267865Z ##[debug]failOnStderr=false
2025-02-20T04:55:36.3268001Z ##[debug]ignoreLASTEXITCODE=false
2025-02-20T04:55:36.3268541Z ##[debug]workingDirectory=/ado/_work/2/s
2025-02-20T04:55:36.3268707Z ##[debug]check path : /ado/_work/2/s
2025-02-20T04:55:36.3270393Z ##[debug]targetType=filePath
2025-02-20T04:55:36.3270554Z ##[debug]filePath=/ado/_work/2/s/_pipelines/ytt/Invoke-KKDeployment.ps1
2025-02-20T04:55:36.3272081Z ##[debug]arguments=-TemplatePath /ado/_work/2/s/_pipelines/ytt/frontend -SchemaPath /ado/_work/2/s/_pipelines/ytt/schema.yaml -EnvironmentDataFilePath /ado/_work/2/s/_pipelines/ytt/staging.yaml -ResourceGroupName rg-s-kk-aue-01 -DeploymentLogPath /ado/_work/2/a/Logs" -Tag 1.964.34287-main -Verbose;
2025-02-20T04:55:36.3278367Z ##[debug]runScriptInSeparateScope=false
2025-02-20T04:55:36.3278532Z Generating script.
2025-02-20T04:55:36.3280890Z ##[debug]Feature flag AZP_75787_ENABLE_NEW_LOGIC_LOG = false
2025-02-20T04:55:36.3281088Z ##[debug]Feature flag AZP_75787_ENABLE_NEW_LOGIC = false
2025-02-20T04:55:36.3281239Z ##[debug]Feature flag AZP_75787_ENABLE_COLLECT = true
2025-02-20T04:55:36.3281379Z ##[debug]Validating file args
2025-02-20T04:55:36.3282134Z ##[debug]Expanded args: -TemplatePath /ado/_work/2/s/_pipelines/ytt/frontend -SchemaPath /ado/_work/2/s/_pipelines/ytt/schema.yaml -EnvironmentDataFilePath /ado/_work/2/s/_pipelines/ytt/staging.yaml -ResourceGroupName rg-s-kk-aue-01 -DeploymentLogPath /ado/_work/2/a/Logs" -Tag 1.964.34287-main -Verbose;
2025-02-20T04:55:36.3285193Z ##[debug]Agent.Version=4.251.0
2025-02-20T04:55:36.3285444Z ##[debug]SYSTEM_TASKINSTANCEID=0359f8e5-dc7f-5078-4192-27f8277c3b6f
2025-02-20T04:55:36.3285824Z ##[debug]SYSTEM_JOBID=3d6941d1-9db5-5975-0b2c-20dbba85b478
2025-02-20T04:55:36.3286002Z ##[debug]SYSTEM_PLANID=59b66946-a5f8-4e68-9c85-a0ab71686119
2025-02-20T04:55:36.3286162Z ##[debug]SYSTEM_COLLECTIONID=316b0f32-b9b6-4c8c-9451-885901a4ed66
2025-02-20T04:55:36.3286315Z ##[debug]AGENT_ID=15243
2025-02-20T04:55:36.3286485Z ##[debug]AGENT_MACHINENAME=build
2025-02-20T04:55:36.3286630Z ##[debug]AGENT_NAME=multipass-1
2025-02-20T04:55:36.3286767Z ##[debug]AGENT_JOBSTATUS=Succeeded
2025-02-20T04:55:36.3286896Z ##[debug]AGENT_OS=Linux
2025-02-20T04:55:36.3287032Z ##[debug]AGENT_VERSION=4.251.0
2025-02-20T04:55:36.3287169Z ##[debug]BUILD_BUILDID=34782
2025-02-20T04:55:36.3287319Z ##[debug]BUILD_BUILDNUMBER=20250220.11
2025-02-20T04:55:36.3287566Z ##[debug]BUILD_BUILDURI=vstfs:///Build/Build/34782
2025-02-20T04:55:36.3287704Z ##[debug]BUILD_CONTAINERID=26922188
2025-02-20T04:55:36.3287855Z ##[debug]BUILD_DEFINITIONNAME=Deploy Frontend - Staging Environment
2025-02-20T04:55:36.3288005Z ##[debug]BUILD_DEFINITIONVERSION=3
2025-02-20T04:55:36.3288135Z ##[debug]BUILD_REASON=Manual
2025-02-20T04:55:36.3288273Z ##[debug]BUILD_REPOSITORY_CLEAN=False
2025-02-20T04:55:36.3288416Z ##[debug]BUILD_REPOSITORY_GIT_SUBMODULECHECKOUT=False
2025-02-20T04:55:36.3288564Z ##[debug]BUILD_REPOSITORY_NAME=device-management
2025-02-20T04:55:36.3288710Z ##[debug]BUILD_REPOSITORY_PROVIDER=TfsGit
2025-02-20T04:55:36.3288867Z ##[debug]BUILD_SOURCEVERSION=91e13a4af4ef93d7772346aba0df07e115c4196c
2025-02-20T04:55:36.3409176Z ##[debug]Processed: ##vso[telemetry.publish area=TaskHub;feature=PowerShellV2]{"SYSTEM_TASKINSTANCEID":"0359f8e5-dc7f-5078-4192-27f8277c3b6f","SYSTEM_JOBID":"3d6941d1-9db5-5975-0b2c-20dbba85b478","SYSTEM_PLANID":"59b66946-a5f8-4e68-9c85-a0ab71686119","SYSTEM_COLLECTIONID":"316b0f32-b9b6-4c8c-9451-885901a4ed66","AGENT_ID":"15243","AGENT_MACHINENAME":"build","AGENT_NAME":"multipass-1","AGENT_JOBSTATUS":"Succeeded","AGENT_OS":"Linux","AGENT_VERSION":"4.251.0","BUILD_BUILDID":"34782","BUILD_BUILDNUMBER":"20250220.11","BUILD_BUILDURI":"vstfs:///Build/Build/34782","BUILD_CONTAINERID":"26922188","BUILD_DEFINITIONNAME":"Deploy Frontend - Staging Environment","BUILD_DEFINITIONVERSION":"3","BUILD_REASON":"Manual","BUILD_REPOSITORY_CLEAN":"False","BUILD_REPOSITORY_GIT_SUBMODULECHECKOUT":"False","BUILD_REPOSITORY_NAME":"device-management","BUILD_REPOSITORY_PROVIDER":"TfsGit","BUILD_SOURCEVERSION":"91e13a4af4ef93d7772346aba0df07e115c4196c","foundPrefixes":0,"someVariablesInsideQuotes":0,"variablesExpanded":0,"escapedVariables":0,"escapedEscapingSymbols":0,"variableStartsFromBacktick":0,"variablesWithBacktickInside":0,"envQuottedBlocks":0,"braceSyntaxEntries":0,"bracedVariables":0,"notClosedBraceSyntaxPosition":0,"bracedEnvSyntax":0,"notExistingEnv":0,"removedSymbols":{";":1},"removedSymbolsCount":1}
2025-02-20T04:55:36.3420587Z ##[debug]Processed: ##vso[task.logdetail id=521e3cbd-cc86-4599-873c-ea51f2b6621b;type=command;name=command;]Formatted command: . '/ado/_work/2/s/_pipelines/ytt/Invoke-KKDeployment.ps1' -TemplatePath /ado/_work/2/s/_pipelines/ytt/frontend -SchemaPath /ado/_work/2/s/_pipelines/ytt/schema.yaml -EnvironmentDataFilePath /ado/_work/2/s/_pipelines/ytt/staging.yaml -ResourceGroupName rg-s-kk-aue-01 -DeploymentLogPath /ado/_work/2/a/Logs" -Tag 1.964.34287-main -Verbose;
2025-02-20T04:55:36.3421014Z ##[debug]Agent.Version=4.251.0
2025-02-20T04:55:36.3421156Z ##[debug]agent.tempDirectory=/ado/_work/_temp
2025-02-20T04:55:36.3421286Z ##[debug]check path : /ado/_work/_temp
2025-02-20T04:55:36.3421384Z ========================== Starting Command Output ===========================
2025-02-20T04:55:36.3421511Z ##[debug]which 'pwsh'
2025-02-20T04:55:36.3421634Z ##[debug]found: '/usr/bin/pwsh'
2025-02-20T04:55:36.3421759Z ##[debug]which '/usr/bin/pwsh'
2025-02-20T04:55:36.3421885Z ##[debug]found: '/usr/bin/pwsh'
2025-02-20T04:55:36.3422010Z ##[debug]/usr/bin/pwsh arg: -NoLogo
2025-02-20T04:55:36.3422136Z ##[debug]/usr/bin/pwsh arg: -NoProfile
2025-02-20T04:55:36.3422259Z ##[debug]/usr/bin/pwsh arg: -NonInteractive
2025-02-20T04:55:36.3422388Z ##[debug]/usr/bin/pwsh arg: -Command
2025-02-20T04:55:36.3422529Z ##[debug]/usr/bin/pwsh arg: . '/ado/_work/_temp/5746ce19-436f-4ddd-bfa1-f3344e169c1e.ps1'
2025-02-20T04:55:36.3422666Z ##[debug]exec tool: /usr/bin/pwsh
2025-02-20T04:55:36.3422794Z ##[debug]arguments:
2025-02-20T04:55:36.3422909Z ##[debug]   -NoLogo
2025-02-20T04:55:36.3423026Z ##[debug]   -NoProfile
2025-02-20T04:55:36.3423147Z ##[debug]   -NonInteractive
2025-02-20T04:55:36.3423259Z ##[debug]   -Command
2025-02-20T04:55:36.3423391Z ##[debug]   . '/ado/_work/_temp/5746ce19-436f-4ddd-bfa1-f3344e169c1e.ps1'
2025-02-20T04:55:36.3423516Z [command]/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command . '/ado/_work/_temp/5746ce19-436f-4ddd-bfa1-f3344e169c1e.ps1'
2025-02-20T04:55:36.5551031Z �[31;1mParserError: �[0m/ado/_work/_temp/5746ce19-436f-4ddd-bfa1-f3344e169c1e.ps1:7�[0m
2025-02-20T04:55:36.5551386Z �[31;1m�[0m�[36;1mLine |�[0m
2025-02-20T04:55:36.5551846Z ##[debug]�[36;1m$LASTEXITCODE:�[0m {0}' -f $LASTEXITCOD …�[0m
2025-02-20T04:55:36.5552067Z �[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m     | �[31;1m                                   ~~~~~~~~~~~~~~�[0m
2025-02-20T04:55:36.5552256Z �[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m     | �[31;1mVariable reference is not valid. ':' was not followed by a valid�[0m
2025-02-20T04:55:36.5552456Z �[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m�[31;1m�[36;1m     | �[31;1mvariable name character. Consider using ${} to delimit the name.�[0m
2025-02-20T04:55:36.5664793Z 
2025-02-20T04:55:36.5666859Z ##[debug]Exit code 1 received from tool '/usr/bin/pwsh'
2025-02-20T04:55:36.5669029Z ##[debug]STDIO streams have closed for tool '/usr/bin/pwsh'
2025-02-20T04:55:36.5673436Z ##[debug]task result: Failed
2025-02-20T04:55:36.5685235Z ##[error]PowerShell exited with code '1'.
2025-02-20T04:55:36.5689356Z ##[debug]Processed: ##vso[task.issue type=error;source=TaskInternal;correlationId=81b1c6c8-7e31-41ce-ad90-64d948e912fe;]PowerShell exited with code '1'.
2025-02-20T04:55:36.5692571Z ##[debug]Processed: ##vso[task.complete result=Failed;]PowerShell exited with code '1'.
2025-02-20T04:55:36.5700129Z ##[section]Finishing: PowerShell 

Repro steps

- task: PowerShell@2
  inputs:
    pwsh: true
    targetType: filePath
    filePath: $(Build.SourcesDirectory)/script.ps1 # Make sure the script has an error.
    arguments: >
       -DeploymentLogPath $(Build.ArtifactStagingDirectory)/Logs
      -Tag $(SEMVER)
      -Verbose;
@jachin84 jachin84 added the bug label Feb 20, 2025
@v-schhabra v-schhabra added Area: ABTT Akvelon Build Tasks Team area of work and removed Area: Release labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: ABTT Akvelon Build Tasks Team area of work bug triage
Projects
None yet
Development

No branches or pull requests

2 participants