How to troubleshoot MissingEndParenthesisInExpression in Azure Yaml Pipelines powershell task arguments

拟墨画扇 提交于 2021-01-29 16:50:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!