6

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?

CharithJ
  • 46,289
  • 20
  • 116
  • 131
leavelllusion
  • 329
  • 5
  • 11
  • Have you considered creating a separate branch/build configuration that *always* deploys to production? It gives you the ability to easily correlate source code to your current production environment, plus it streamlines the CI and deployment processes. 'publishing' becomes synonymous with merging to the appropriate branch – Jared Dykstra Nov 20 '15 at 15:23

2 Answers2

0

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.

Mecaveli
  • 1,507
  • 10
  • 16
0

Yes, you can make a build configuration to prompt for parameter values.

Edit Spec

enter image description here

Then you can customize the prompt display

enter image description here

CharithJ
  • 46,289
  • 20
  • 116
  • 131