azure-devops - Azure devops 管道 CmdLine 任务脚本错误
问题描述
嗨,我是 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 管道 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
}
}
您可以查看此线程以获取更多详细信息。
推荐阅读
- regex - mark.js 的非贪婪正则表达式
- r - 错误是在 dplyr 包中使用绝对差异?
- javascript - 在 twilio 中暂停和恢复房间的视频录制?
- scala - 从scala中的json数组获取数据
- amazon-web-services - 为什么 lambda 函数在测试中不输出我的标头?
- visual-studio-code - Visual Studio (VS-code) 代码终端无法启动
- javascript - 如何使用 puppeteer 自动填写 shopify 付款页面
- docker - 使用主机挂载目录时缺少 Configset 目录
- javascript - POST 请求错误 - Express 服务器 - React Native 网络请求失败
- javascript - ReactDOM.render 没有渲染所有的 Id