Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure DevOps-管道不应触发PR的生成_Azure_Github_Azure Devops_Azure Pipelines - Fatal编程技术网

Azure DevOps-管道不应触发PR的生成

Azure DevOps-管道不应触发PR的生成,azure,github,azure-devops,azure-pipelines,Azure,Github,Azure Devops,Azure Pipelines,我有一个用于Git存储库的Azure DevOps管道。我目前有一个脚本来验证Azure管道中的PR注释 当代码合并到主分支中时,我想触发一个构建。我不知道如何通过Azure DevOps管道实现这一点 #Trigger for Development trigger: branches: include: - development - master #Trigger checks for PR pr: branches: include:

我有一个用于Git存储库的Azure DevOps管道。我目前有一个脚本来验证Azure管道中的PR注释

当代码合并到主分支中时,我想触发一个构建。我不知道如何通过Azure DevOps管道实现这一点

#Trigger for Development
trigger:
 branches:
   include:
     - development
     - master
#Trigger checks for PR
pr: 
 branches:
    include:
      - development
      - master
      - feature
      - main
 paths:
   exclude:
     - README/*
当代码合并到主分支中时,我想触发构建

如果要在代码合并到主分支后验证注释,我们需要在PR完成后而不是在创建PR时触发构建

因此,在这种情况下,系统无法满足我们的要求

为了解决这个问题,我们可以使用**条件**
eq(变量['Commitcomment'],'Merge pull request')
为脚本任务启用CI触发器,以验证PR注释

在这种情况下,管道将仅在
Commitcomment
Merge pull request
时执行作业,这可以过滤出PR未完成的修改

要获取变量
Commitcomment
的值,我们可以通过变量
Build.SourceVersionMessage
检查github上的提交消息:

如果提交来自PR,它将给出一个默认注释,从:
Merge pull request xxx
开始,我们可以添加一个bash\powershell脚本来获取前几个字段

然后,如果前几个字段是合并请求,则使用将变量
Commitcomment
设置为true:

  - task: CmdLine@2
    displayName: get the first few fields
    inputs:
      script: >-
        echo $(Build.SourceVersionMessage)
        set  TempVar=$(Build.SourceVersionMessage)
        set Commitcomment=%TempVar:~0,18%
        echo %Commitcomment%
        echo ##vso[task.setvariable variable=Commitcomment]%Commitcomment%
参考链接:

然后将此变量作为条件添加到任务中,以验证PR注释:

  - task: CmdLine@2
    displayName: script to validate the PR comments
    condition: and(succeeded(), eq(variables['Commitcomment'], 'Merge pull request'))
    inputs:
      script: >
        echo To validate the PR comments
在这种情况下,如果提交不是来自PR,它将跳过PR注释验证任务:

当代码合并到主分支中时,我想触发构建

如果要在代码合并到主分支后验证注释,我们需要在PR完成后而不是在创建PR时触发构建

因此,在这种情况下,系统无法满足我们的要求

为了解决这个问题,我们可以使用**条件**
eq(变量['Commitcomment'],'Merge pull request')
为脚本任务启用CI触发器,以验证PR注释

在这种情况下,管道将仅在
Commitcomment
Merge pull request
时执行作业,这可以过滤出PR未完成的修改

要获取变量
Commitcomment
的值,我们可以通过变量
Build.SourceVersionMessage
检查github上的提交消息:

如果提交来自PR,它将给出一个默认注释,从:
Merge pull request xxx
开始,我们可以添加一个bash\powershell脚本来获取前几个字段

然后,如果前几个字段是合并请求,则使用将变量
Commitcomment
设置为true:

  - task: CmdLine@2
    displayName: get the first few fields
    inputs:
      script: >-
        echo $(Build.SourceVersionMessage)
        set  TempVar=$(Build.SourceVersionMessage)
        set Commitcomment=%TempVar:~0,18%
        echo %Commitcomment%
        echo ##vso[task.setvariable variable=Commitcomment]%Commitcomment%
参考链接:

然后将此变量作为条件添加到任务中,以验证PR注释:

  - task: CmdLine@2
    displayName: script to validate the PR comments
    condition: and(succeeded(), eq(variables['Commitcomment'], 'Merge pull request'))
    inputs:
      script: >
        echo To validate the PR comments
在这种情况下,如果提交不是来自PR,它将跳过PR注释验证任务:


如果您只想在特定分支中完成合并(拉请求已验证)时启动生成,那么您的代码是好的

如果当前要运行验证生成,则它未集成到Yaml pippeline配置()

为此,必须通过图形界面完成: 项目设置->存储库->选择您的回购->策略->分支策略->选择您的分支->生成验证->+->添加生成信息


()

如果您只想在特定分支中完成合并(pull请求已验证)时启动构建,那么您的代码是好的

如果当前要运行验证生成,则它未集成到Yaml pippeline配置()

为此,必须通过图形界面完成: 项目设置->存储库->选择您的回购->策略->分支策略->选择您的分支->生成验证->+->添加生成信息


()

我的分支是一个GitHub分支,我不确定是否仍然可以向其中添加分支策略@Rasmi、Github受保护的分支可供Pro、Team和Enterprise用户使用,不支持免费帐户。此外,即使我们有受Github保护的分支,它仍然不能满足您的需要。Github Protected Branchs设置的构建验证在PR打开时触发,但如果在触发构建后在PR中添加注释,则不会验证新添加的注释。我们需要在PR完成后验证所有评论。我的分支是GitHub分支,我不确定是否仍然可以向其添加分支策略@Rasmi、Github受保护的分支可供Pro、Team和Enterprise用户使用,不支持免费帐户。此外,即使我们有受Github保护的分支,它仍然不能满足您的需要。Github Protected Branchs设置的构建验证在PR打开时触发,但如果在触发构建后在PR中添加注释,则不会验证新添加的注释。公关完成后,我们需要验证所有评论。@Rasmi,我已经用更详细的信息和脚本更新了我的答案,希望对您有所帮助。祝你度过愉快的一天。我用过这个,工作得很好!!谢谢@拉斯米,我已经用更详细的信息和脚本更新了我的答案,希望它能帮助你。祝你度过愉快的一天。我用过这个,工作得很好!!谢谢