Azure devOps 构建管道 : Force fail yaml step. bash 以防出现 isql 问题

标签 azure azure-devops azure-pipelines pipeline isqlquery

在我的构建 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.

结果:

enter image description here

所以把它放在你想让任务失败的地方。

关于Azure devOps 构建管道 : Force fail yaml step. bash 以防出现 isql 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74378368/

相关文章:

azure-devops - Azure DevOps : Assets file doesn't have a target for '.NETCoreApp,Version=v2.2/linux-x64'

azure - 访问 Azure 存储库时收到 403 禁止

c# - 在 Nuget 包中公开 Azure Functions

Azure Functions-新-AzContainerGroup : Object reference not set to an instance of an object

azure - 如何在 Azure 数据工厂 (ADF) 自定义事件中注入(inject)依赖项?

Azure Devops API - 获取顶级组合工作项类型

azure - 来自服务器的错误(禁止): error when retrieving current configuration | Azure Pipelines

for-loop - 在 azure 管道作业中使用 for 循环

azure-devops - 提供具有默认值的管道队列时间变量

azure - 根据 Azure 表数据模型约定动态重命名/映射列