可以通过带有某些参数的github pr注释触发构建 [英] Possible to trigger a build via github pr comment with some arguments

查看:153
本文介绍了可以通过带有某些参数的github pr注释触发构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够通过Github评论触发构建.我已经工作了,但是有点限制.就我而言,我有3个或4个命名部署目标,并希望触发部署到其中一个部署的管道.没有任何上下文可以指示我的首选环境是什么,因此我只想成为一个变量.

I would like to able to trigger a build via a Github comment. I've got that working however its a bit limiting. In my case, I have 3 or 4 named deployment targets and would like to trigger a pipeline that deployed to one of those deployments. There's nothing contextually indicative of what my preferred environment would be so I want to just be a variable.

类似: /AzurePipelines运行Deploy env = test foo = bar

Something like: /AzurePipelines run Deploy env=test foo=bar

这可能吗?如果没有,没有人有一个聪明的解决方法吗?

Is this possible? If not does anyone have a clever workaround?

当前,我已将管道的相关部分移至模板,并且每个环境都利用该模板创建了一个管道.但这会产生令人不快的噪音.

Currently, I have moved relevant portions of the pipeline to a template and have a pipeline per env leveraging that template. This creates an unpleasant amount of noise though.

推荐答案

您可以使用

此变量是代理作用域的,可用作脚本中的环境变量和构建任务中的参数

This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task

因此您可以在管道顶部添加一个powershell任务,以获取PR提交消息.然后从提交消息中提取(使用正则表达式或json)属性和值.然后,您可以为您的管道将提取的属性设置为环境变量" .

So that You can add a powershell task at the top of your pipeline to get the your PR commit message. and then extract (using regular expression or json) the properties and values from the commit message. Then you can set the extracted properties to Env Variables for your pipeline.

下面是一个简单的示例,当我创建pr时,我将提交消息设置为json字符串{"env":"test" "foo":"bar"}.然后在脚本中提取env和foo属性及其值,并将它们设置为管道变量.

Below is a simple example, When I create a pr, I set the commit message to a json string {"env":"test" "foo":"bar"}. And I extract the env and foo properties and their values in the scripts and set them to pipeline variables.

variables:
  env: ""
  foo: ""
steps:
- task: PowerShell@2
  displayName: 'Get Variables'
  inputs:
    targetType: inline
    script: |
      $data= '$(Build.SourceVersionMessage)'
      write-host $data
      $variables= $data | ConvertFrom-Json
      $variables.PSObject.Properties | foreach {Write-host "##vso[task.setvariable variable=$_.Name]$_.Value"}

然后,您可以根据提交消息在以下任务中使用变量.

Then you can use the variables in the following tasks according to your commit message.

希望上面有帮助!

这篇关于可以通过带有某些参数的github pr注释触发构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆