简体   繁体   中英

How can I prompt TeamCity configuration parameter for meta-runner?

I want to create meta-runner that will ask user to check checkbox ('prompt' configuration parameter) to confirm deployment to production. It contains powershell script that validate if checkbox is checked. Here is code of 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) The first thing is that parameter deploy.to.production.confirmation.checkbox is not working as expected and not showing confirmation dialog on each build, I can only specify it on step configuration page.

2) The second thing is that if I will add deploy.to.production.confirmation.checkbox parameter to my build configuration, it will prompt value as expected but this value will be not passed to Powershell script.

How can I ask user to specify some value (before running build configuration) and then pass this value to Powershell script?

The <parameters> section declares build step level parameters, that´s why you don´t get a promt on the build. To get that, you´ll have to declare the deploy.to.production.confirmation.checkbox parameter in the build configuration.

Then you can take that value and pass it to the MetaRunner like this:

<param name="deploy.to.production.confirmation.checkbox" value="%deploy.to.production.confirmation.checkbox%" />

On a sidenote, i agree with Jared Dykstra´s comment. You should consider creating seperate build configurations for this task.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM