Azure DevOps 作业忽略失败

Mic*_*l B 6 azure azure-devops

我的 azure-pipelines.yml 中有以下内容

jobs:
- job: TestifFolder1Exists
  pool:
    vmImage: 'ubuntu-16.04'

  steps:
  - bash: git log -1 --name-only | grep -c Folder1
    failOnStderr: false

- job: Folder1DoesntExist
  pool:
    vmImage: 'ubuntu-16.04'
  dependsOn: TestifFolder1Exists
  condition: failed() 

- job: Folder1DoesExist
  pool:
    vmImage: 'ubuntu-16.04'
  dependsOn: TestifFolder1Exists
  condition: succeeded() 
Run Code Online (Sandbox Code Playgroud)

我正在尝试测试文件夹是否进行了更改,以便我可以从该目录发布工件。

我遇到的问题是,如果没有任何内容写入文件夹,脚本将失败 Bash exited with code '1'.(这是我想要的),这反过来会使整个构建失败。

如果我添加,continueOnError则以下作业始终运行成功的作业。

我怎样才能让这项工作失败,而不会使整个构建失败?

My *_*ife 9

有一个选项叫做continueOnError。默认设置为 false。将此更改为 true,您的任务不会停止构建作业。

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/tasks?view=azure-devops&tabs=yaml#controloptions

  • 使用“continueOnError”,失败的任务会将状态设置为“SucceededWithIssues”。构建不会失败,但会成功并显示警告符号。 (6认同)
  • 但是如果这个任务失败了,构建会失败吗? (4认同)

Mic*_*l B 6

我不知道如何忽略失败的工作,但这就是我解决这个特定问题的方法

jobs:
- job: TestifFolder1Exists
  pool:
    vmImage: 'ubuntu-16.04'

  steps:
  - bash: |
      if [ "$(git log -1 --name-only | grep -c Folder1)" -eq 1 ]; then 
        echo "##vso[task.setVariable variable=Folder1Changed]true"
      fi
  - bash: echo succeeded
    displayName: Perform some task
    condition: eq(variables.Folder1Changed, 'true') 
Run Code Online (Sandbox Code Playgroud)

(虽然事实证明 Azure Devops 已经完成了我在这里尝试创建的内容 - 路径过滤器触发!)