我想创建元运行器,它将要求用户选中复选框('prompt'配置参数)以确认部署到生产。它包含powershell脚本,用于验证是否选中了复选框。这是meta-runner的代码:
<?xml version="1.0" encoding="UTF-8"?>
<meta-runner name="Confirm deploy to production">
<description>Force user to check checkbox to confirm deploy to production</description>
<settings>
<parameters>
<param name="deploy.to.production.confirmation.checkbox" value="false" spec="checkbox description='Are you sure?' label='This is deployment to PRODUCTION environment.' uncheckedValue='false' display='prompt' checkedValue='true'" />
</parameters>
<build-runners>
<runner name="Confirm deploy to production" type="jetbrains_powershell">
<parameters>
<param name="jetbrains_powershell_bitness" value="x86" />
<param name="jetbrains_powershell_errorToError" value="false" />
<param name="jetbrains_powershell_execution" value="PS1" />
<param name="jetbrains_powershell_script_code"><![CDATA[trap
{
write-output $_
##teamcity[buildStatus status='FAILURE' ]
exit 1
}
write-host "##teamcity[message text='Starting confirmation validation...']"
if("%deploy.to.production.confirmation.checkbox%" -eq "false"){
write-host "##teamcity[message text='Confirmation validation FAILED' errorDetails='This is a production deployment. The confirm checkbox must be checked to proceed with the deploy process.' status='ERROR']"
throw "Confirmation validation FAILED"
} else {
write-host "##teamcity[message text='Confirmation validation SUCCESSFUL']"
}]]></param>
<param name="jetbrains_powershell_script_mode" value="CODE" />
<param name="teamcity.step.mode" value="default" />
</parameters>
</runner>
</build-runners>
<requirements />
</settings>
</meta-runner>
1)第一件事是参数deploy.to.production.confirmation.checkbox
没有按预期工作,并且没有在每个构建上显示确认对话框,我只能在步骤配置页面上指定它。
2)第二件事是,如果我将deploy.to.production.confirmation.checkbox
参数添加到我的构建配置中,它将按预期提示值,但此值不会传递给Powershell脚本。
如何让用户指定一些值(在运行构建配置之前),然后将此值传递给Powershell脚本?
答案 0 :(得分:0)
<parameters>
部分声明构建步骤级别参数,这就是为什么你没有在构建上获得promt的原因。为此,您必须在构建配置中声明deploy.to.production.confirmation.checkbox
参数。
然后您可以将该值传递给MetaRunner,如下所示:
<param name="deploy.to.production.confirmation.checkbox" value="%deploy.to.production.confirmation.checkbox%" />
在旁注中,我同意Jared Dykstra的评论。您应该考虑为此任务创建单独的构建配置。