Azure devOps build pipeline: Force fail yaml step.bash in case of isql issue

586 Views Asked by At

In my build yaml pipeline, I have a step.bash to connect to isql and run a select query. I have a requirement to fail/exit the step in case of any issue in isql and retry 2nd time.

However, Azure devops is marking step.bash as success and skipping the 2nd retry.

Is there anyway to fail the bash.step forcefully?

I tried RAISEERROR and azure devops logging commands inside the isql but no luck.

here's the step:

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

1

There are 1 best solutions below

1
On

exit 1 will force the task to fail.

I write a demo:

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.

Result:

enter image description here

So put it in the place where you want to make the task fail.