【问题标题】:Azure devops pipeline CmdLine Task script errorAzure devops 管道 CmdLine 任务脚本错误
【发布时间】:2021-07-26 13:06:40
【问题描述】:

您好,我是 AzureDevops 和管道的新手,我正在尝试使用脚本创建一个 CmdLine 任务,该脚本根据此处的分支名称设置一些变量:

- task: CmdLine@2
  displayName: Find Branch type
  inputs:
   script: |
     IF contains($(Build.SourceBranch), 'release')==True (set isLongBranch=True
      ) ELSE IF contains($(Build.SourceBranch), 'support') (set isLongBranch=True
      ) ELSE IF contains($(Build.SourceBranchName), 'develop') (set isLongBranch=True
      ) ELSE IF contains($(Build.SourceBranchName), 'master') (set isLongBranch=True
      ) ELSE IF contains($(Build.SourceBranch), 'hotfix') (set isLongBranch=True
      ) ELSE (set isLongBranch=False)
     IF contains($(Build.SourceBranch), 'release') (set isSonar=True
      ) ELSE IF contains($(Build.SourceBranch), 'support'), 'support')] (set isSonar=True
      ) ELSE IF contains($(Build.SourceBranchName), 'develop') (set isSonar=True
      ) ELSE IF contains($(Build.SourceBranchName), 'master') (set isSonar=False
      ) ELSE IF contains($(Build.SourceBranch), 'hotfix') (set isSonar=True
      ) ELSE IF contains($(Build.SourceBranch), 'feature') (set isSonar=True
      ) ELSE IF %isPoolRequest%==True (set isSonar=False
      ) ELSE (set isSonar=False)
      #echo $(Build.SourceBranch)
      #echo $(Build.SourceBranchName)

我得到的错误是:

'release')==True 出乎意料。 ##[错误]Cmd.exe 已停止。退出代码:'255'。

【问题讨论】:

  • 这个问题怎么样?下面的答案是否解决了您的问题,如果没有,请告诉我有关此问题的最新信息吗?

标签: azure-devops azure-pipelines


【解决方案1】:

Azure devops 管道 CmdLine 任务脚本错误

如果我使用与您相同的代码,我会遇到与您相同的错误。

一般我们使用findstr来检查变量是否包含子字符串,比如:

echo $(Build.SourceBranch) | findstr "release" >nul &&(
    echo "include"
)

或者,您可以使用 powershell 脚本来执行此操作:

$files = @("$(Build.SourceBranch)")
$excludeTypes = @("*release*","*support*", "*master*")

    foreach ($type in $excludeTypes) {
        if ($file -like $type) { 
            Write-Host ("Match found: {0} matches {1}" -f $file, $type)
            $Env:isLongBranch = true
        } 
          else
        {
          $Env:isLongBranch = False
        }
    }

您可以查看this thread 了解更多详情。

【讨论】:

    猜你喜欢
    • 2021-12-18
    • 1970-01-01
    • 2020-01-18
    • 2022-08-24
    • 2023-04-08
    • 1970-01-01
    • 2022-12-01
    • 2020-08-27
    • 2021-01-20
    相关资源
    最近更新 更多