问题
yaml PowerShell task looks something like this:
- task: PowerShell@2
displayName: 'test'
inputs:
targetType: filePath
filePath: '$(Agent.BuildDirectory)\$(artifactName)\testpath\testscript.ps1'
arguments: '-parameterFilePath $(Agent.BuildDirectory)\$(artifactName)\mainfolder\params.json -appSecurePassword (convertTo-SecureString $(appPassword) -AsPlainText -Force) -vmSecurePassword (convertTo-SecureString $(vmPassword) -AsPlainText -Force)'
However, I get this error:
2020-06-09T12:54:59.6954669Z At C:\agent_work_temp\66085384-0a17-4183-9832-42c481b13a84.ps1:3 char:352
2020-06-09T12:54:59.6974788Z + ... urePassword (convertTo-SecureString *** -AsPlainText -Force)
2020-06-09T12:54:59.7070327Z + ~
2020-06-09T12:54:59.7124752Z Missing closing ')' in expression.
2020-06-09T12:54:59.7142356Z + CategoryInfo : ParserError: (:) [], ParseException
2020-06-09T12:54:59.7161695Z + FullyQualifiedErrorId : MissingEndParenthesisInExpression
2020-06-09T12:54:59.7173148Z
2020-06-09T12:54:59.8102255Z ##[error]PowerShell exited with code '1'.
Can anyone please let me know what I am missing? I am sure there is no problem with the PowerShell script as I can run that manually on the agent.
回答1:
The above error message ... urePassword (convertTo-SecureString *** -AsPlainText -Force)
indicates the issue comes from the arguments
of powershell task.
And the error Missing closing ')' in expression
indicates that there is "(" character in your Password.
I tested on my pipeline, if my password is "pass(word"(without double quotes). I got the same Missing closing ')'
error message.
You can try double quoting your passwords when you refer to them in the arguments
. See below:
-appSecurePassword (convertTo-SecureString "$(appPassword)" -AsPlainText -Force) -vmSecurePassword (convertTo-SecureString "$(vmPassword)" -AsPlainText -Force)
You can also try using backtick to escape the special characters in the password. For example, escape the special characters in the Passwords defined in the pipeline Variables (eg. "pass`(word")
See Passwords Containing Special Characters In PowerShell for more information.
回答2:
With Azure YAML pipelines one way to debug would be to select "Enable system Diagnostic" on your pipeline when your run:
After running it you can download the logs:
After downloading look at the azure-pipelines-expanded.yml This will be the full yaml your pipeline is running with all templates included. This should give you a complete picture of what is being executed.
来源:https://stackoverflow.com/questions/62286251/how-to-troubleshoot-missingendparenthesisinexpression-in-azure-yaml-pipelines-po