Home > Enterprise >  Azure Pipeline skip failed task and ignore fail in build process
Azure Pipeline skip failed task and ignore fail in build process

Time:03-31

I have a task inside an Azure Pipeline Job which is failing. In my case the fail of the task isn't important so I want to know if it is possible to skip the failed task and execute the following tasks normally, without marking the whole Job as Failed or Partially Succeeded. I want the Job to still be a Success if the other Tasks were executed properly.

The pipeline is executed manually and the task in question commits a git repository via a CMD-Script. The Job downloads the repository, rewrites some files inside, and then commits and pushes it. The rewritten files might end up with the same content as before, therefore git does not recognize any changes and the commit fails.

The task:

  - task: CmdLine@2
    displayName: 'Commit Repository'
    inputs:
      script: 'git commit -am "Commited by pipeline"'
      workingDirectory: '$(SYSTEM.DEFAULTWORKINGDIRECTORY)'
    continueOnError: true

The error:

On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

##[error]Cmd.exe exited with code '1'.

I am keeping the job from failing with continueOnError: true, but this marks the Job and therefore the pipeline build as Build partially succeeded with an orange !-icon.

I've also tried to redirect the error from CMD with > nul, 2> nul, and > nul 2>&1, but this only hides the error message, not the error itself. Or at least not from the pipeline build.

Is there any way to "hide" a CMD-Error from the pipeline so that the task is still marked as a success?

Or is continueOnError: true the best I can do?

Thanks for your help

CodePudding user response:

Beside continueOnError: true, you can try a script which returns 0:

script: 'git commit -am "Committed by pipeline"; exit 0'

Or

script: |
  git commit -am "Committed by pipeline
  exit 0

That way, the exit status of the script would be 0 (success), even if the commit fails (because there is nothing to commit).

  • Related