在我的构建 yaml 管道中,我有一个 step.bash 用于连接到 isql 并运行选择查询。如果 isql 中出现任何问题,我需要失败/退出该步骤并重试第二次。
但是,Azure devops 将 step.bash 标记为成功并跳过第二次重试。
是否有办法强制使 bash.step 失败?
我在 isql 中尝试了 RAISEERROR 和 azure devops 日志记录命令,但没有成功。
步骤如下:
steps:
- bash: |
isql -U ${{ User }} -P ${{ Password }} -S ${{ Server }} -D ${{ Database }} <<-EOSQL
USE master
GO
Select * from table (If this query fails with error code 102)
IF @@error = 102
RAISERROR 17001 "Unable to login"
GO
EOSQL
echo "##vso[task.setvariable variable=dataset]ok"
displayName: Test dataset
enabled: true
condition: ne(variables['dataset'], 'ok')
continueOnError: true
最佳答案
exit 1
将强制任务失败。
我写了一个演示:
trigger:
- none
pool:
vmImage: ubuntu-latest
steps:
- task: Bash@3
inputs:
targetType: 'inline'
script: |
# Write your commands here
exit 1 #This will make the task fail.
# exit 0 #This will make the task success.
结果:
所以把它放在你想让任务失败的地方。
关于Azure devOps 构建管道 : Force fail yaml step. bash 以防出现 isql 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74378368/