简体   繁体   English

无法在 Azure DevOps 管道“解析错误”中运行 PowerShell 脚本

[英]Can't run PowerShell script in Azure DevOps Pipeline 'parse error'

So, I'm new to Azure Devops (but not Azure or PowerShell).所以,我是 Azure Devops 的新手(但不是 Azure 或 PowerShell)。 I've got two scripts as tasks in my pipeline, the first runs perfectly (Note: no az module commands).我的管道中有两个脚本作为任务,第一个运行完美(注意:没有 az module 命令)。 The second one fails (It has one Az call).第二个失败(它有一个 Az 调用)。 The error I get in the pipeline is:我在管道中遇到的错误是:

ParserError: /home/vsts/work/_temp/3f7b3ce1-6afb-46f3-b00d-1efe35fbac71.ps1:5
Line |
   5 |  } else {
     |  ~
     | Unexpected token '}' in expression or statement.

Here is the thing... I don't have '} else {' in my script or at least, I removed it and got the same error.事情是这样的......我的脚本中没有'} else {',或者至少,我删除了它并得到了同样的错误。

So whatever is causing this is more fundamental than my script.所以无论是什么原因,都比我的脚本更根本。 I assumed that '/home/vsts/work/_temp/3f7b3ce1-6afb-46f3-b00d-1efe35fbac71.ps1' was my script copied to the remote syste, but it doesn't seem to be the case.我认为“/home/vsts/work/_temp/3f7b3ce1-6afb-46f3-b00d-1efe35fbac71.ps1”是我复制到远程系统的脚本,但似乎并非如此。

Is there any way, I can find out what that file is?有什么办法,我可以找出那个文件是什么?

The task is 'PowerShell@2' with 'pwsh: true' set.任务是设置了“pwsh: true”的“PowerShell@2”。 Thanks!谢谢!

YAML: YAML:

trigger:
- main

pool:
  vmImage: ubuntu-latest

steps:
- task: AzureResourceManagerTemplateDeployment@3
  inputs:
    deploymentScope: 'Resource Group'
    azureResourceManagerConnection: 'Pay-As-You-Go(<guid>)'
    subscriptionId: '<guid>'
    action: 'Create Or Update Resource Group'
    resourceGroupName: 'project-Test'
    location: 'East US 2'
    templateLocation: 'Linked artifact'
    csmFile: 'deploy.template.json'
    csmParametersFile: 'deploy.parameters.json'
    deploymentMode: 'Incremental'
    deploymentOutputs: 'DeploymentOutput'

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: $(System.DefaultWorkingDirectory)/Get-ArmDeploymentOutput.ps1 -ArmOutputString '$(DeploymentOutput)' -MakeOutput -ErrorAction Stop
    pwsh: true
  displayName: Get-ArmDeploymentOutput

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: $(System.DefaultWorkingDirectory)/Set-AzWebAppIPRestriction.ps1 -Priority 100 -Action 'Allow' -WebAppId '$(WebAppId)' -PipId '$(gwpipId)'' -ErrorAction Stop
    pwsh: true
  displayName: Set-AzWebAppIPRestriction

I found there is an extra ' in -PipId '$(gwpipId)'' in the script of your second powershell task.我发现在您的第二个 powershell 任务的脚本中有一个额外' in -PipId '$(gwpipId)'' Maybe it caused the error.也许它导致了错误。

script: $(System.DefaultWorkingDirectory)/Set-AzWebAppIPRestriction.ps1 -Priority 100 -Action 'Allow' -WebAppId '$(WebAppId)' -PipId '$(gwpipId)'' -ErrorAction Stop

Since you were running your scripts in.ps1 file.由于您在.ps1 文件中运行脚本。 You should change the targetType parameter of powershell task to filePath .您应该将powershell 任务targetType参数更改为filePath And set.ps1 file in the filePath parameter.并在filePath参数中设置.ps1文件。 See below example:请参见下面的示例:

steps:
- task: PowerShell@2
  displayName: 'PowerShell Script'
  inputs:
    targetType: filePath
    filePath: '$(System.DefaultWorkingDirectory)/Set-AzWebAppIPRestriction.ps1'
    arguments: '-Priority 100 -Action "Allow" -WebAppId "$(WebAppId)" -PipId "$(gwpipId)" -ErrorAction Stop'
    pwsh: true

If you are using azure powershell module in your scripts.如果您在脚本中使用 azure powershell 模块。 You can use Azure powershell task instead of powershell task..您可以使用Azure powershell 任务代替 powershell 任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure DevOps 发布管道 Azure CLI Powershell 任务找不到 Z2F2D399F0EA80FE47B3459 - Azure DevOps Release pipeline Azure CLI Powershell task can't find powershell azure devops 管道脚本给出了 bash 错误 - azure devops pipeline script is giving bash error Azure DevOps 管道中的命令行脚本出错 - Error with Command Line Script in Azure DevOps Pipeline Azure devops 管道中的命令行脚本错误 - Command line script error in Azure devops pipeline Azure Devops 管道运行使 Git 错误? - Azure Devops Pipeline Run makes Git Error? 在运行 Powershell 脚本的 Azure DevOps 管道中传递脚本参数 - Pass a script argument in Azure DevOps pipeline which runs a Powershell script Azure Powershell脚本:解析错误 - Azure Powershell Script: Parse Error 如何将 Powershell 脚本文件路径从 azure devops repo 传递到 Azure devops 构建管道 - how to pass Powershell script filepath from azure devops repo into Azure devops build pipeline 如何通过 azure devops 管道运行 AzureRM 脚本 - How to run AzureRM script via azure devops pipeline Azure DevOps:如何从 Release Pipeline 中的 PowerShell 脚本构建 Azure Pipeline 检索构建工件? - Azure DevOps: How to retrieve a build artifact from build Azure Pipeline from a PowerShell Script in Release Pipeline?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM